lxyu/17monip — pull request #7 by cadl (2014-11-20 17:37:37+00:00)
Title: Use binary search instead of line search. And Fix '保留地址' issue.

hi, folks:
I use binary search to replace line search. And I do a simple benchmark. The total query time down to 3.5s from 20s.
The benchmark script like this:

import time
from IP import IPv4Database

db = IPv4Database()

st = time.time()
for i in xrange(0, 256*256*256*256, 17173):
ip = [0, 0, 0, 0]
cnt = 0
while i > 0:
ip[cnt] = i % 256
i = i / 256
cnt += 1
db._lookup_ipv4('.'.join(map(str, ip)))
en = time.time()

print en - st

And I found a issue. Some IP should be mapped to '保留地址', not 'None', like '0.42.134.0'.