File: benchmark.py

package info (click to toggle)
python-maxminddb 1.2.3-1~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 1,880 kB
  • sloc: python: 1,052; ansic: 476; perl: 428; makefile: 137; sh: 43
file content (35 lines) | stat: -rw-r--r-- 974 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/python
# -*- coding: utf-8 -*-

from __future__ import print_function

import argparse
import maxminddb
import random
import socket
import struct
import timeit

parser = argparse.ArgumentParser(description='Benchmark maxminddb.')
parser.add_argument('--count', default=250000, type=int,
                    help='number of lookups')
parser.add_argument('--mode', default=0, type=int,
                    help='reader mode to use')
parser.add_argument('--file', default='GeoIP2-City.mmdb',
                    help='path to mmdb file')

args = parser.parse_args()

reader = maxminddb.open_database(args.file, args.mode)


def lookup_ip_address():
    ip = socket.inet_ntoa(struct.pack('!L', random.getrandbits(32)))
    record = reader.get(str(ip))


elapsed = timeit.timeit('lookup_ip_address()',
                        setup='from __main__ import lookup_ip_address',
                        number=args.count)

print(args.count / elapsed, 'lookups per second')