Skip to content

Commit 42f831d

Browse files
committed
added maxmind_test.py, to test the class
1 parent 91682ae commit 42f831d

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

maxmind_test.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/python
2+
#
3+
# maxmind_test.py
4+
#
5+
# A test script for the maxmind class
6+
#
7+
# Initials:
8+
# AX Axel Roest
9+
#
10+
# Version history
11+
# 20120710 AR first version
12+
#
13+
# ToDO:
14+
#
15+
16+
import sys
17+
import re
18+
import os
19+
import math
20+
import bisect
21+
from datetime import datetime
22+
import MySQLdb
23+
import random
24+
from maxmind import MaxMind
25+
26+
# test
27+
28+
mm = MaxMind(db_host, db_user, db_passwd, db_name, db_filetable)
29+
ip = 67276848
30+
loc = mm.lookup(ip)
31+
print str(ip) + ' : ' + str(loc)
32+
33+
ip = 67277000
34+
loc = mm.lookup(ip)
35+
print str(ip) + ' : ' + str(loc)
36+
37+
ip = 67277023
38+
loc = mm.lookup(ip)
39+
print str(ip) + ' : ' + str(loc)
40+
41+
ip = 67277024
42+
loc = mm.lookup(ip)
43+
print str(ip) + ' : ' + str(loc)
44+
45+
testamount = 100000
46+
start_time = datetime.now()
47+
for i in range(testamount):
48+
r = random.randint(33996344, 3741319167)
49+
loc = mm.lookup(r)
50+
end_time = datetime.now()
51+
totaltime = end_time - start_time
52+
timeperlookup = totaltime / testamount
53+
print '=====================================\nLookup ' + str(testamount) + ' ips in ' + str(totaltime) + ' seconds = ' + str(timeperlookup) + ' seconds per lookup'

0 commit comments

Comments
 (0)