a little more clear on the speed test

This commit is contained in:
John Dickinson 2015-02-15 11:49:50 -08:00
parent 918a341b2c
commit 2efb2c2ba2
1 changed files with 12 additions and 11 deletions

23
test_slogging/speed/test_cidr_speed.py Executable file → Normal file
View File

@ -8,6 +8,7 @@ from slogging import access_processor
class TestAccessProcessorSpeed(unittest.TestCase):
def test_CIDR_speed(self):
line = 'Sep 16 20:00:02 srv testsrv 192.%s.119.%s - ' \
'16/Sep/2012/20/00/02 GET /v1/a/c/o HTTP/1.0 ' \
@ -35,16 +36,10 @@ class TestAccessProcessorSpeed(unittest.TestCase):
(orig_end - orig_start).microseconds))
self.assertEqual(hit, 255)
# now, let's check the speed with pure dicts
dict1 = set(k for k in
iptools.IpRangeList(*[x.strip() for x in
'127.0.0.1,192.168/16,10/24'.split(',') if x.strip()]))
dict2 = set(k for k in
iptools.IpRangeList(*[x.strip() for x in
'172.168/16,10/30'.split(',') if x.strip()]))
dict3 = set(k for k in
iptools.IpRangeList(*[x.strip() for x in
'127.0.0.1,11/24'.split(',') if x.strip()]))
# now, let's check the speed with sets
set1 = set(k for k in ips1)
set2 = set(k for k in ips2)
set3 = set(k for k in ips3)
new_start = datetime.datetime.utcnow()
hit = 0
@ -52,10 +47,16 @@ class TestAccessProcessorSpeed(unittest.TestCase):
for a in range(255):
stream = line % (n, a)
data = stream.split(" ")
if data[5] in dict1 or data[5] in dict2 or data[5] in dict3:
if data[5] in set1 or data[5] in set2 or data[5] in set3:
hit += 1
new_end = datetime.datetime.utcnow()
new_secs = float("%d.%d" % ((new_end - new_start).seconds,
(new_end - new_start).microseconds))
self.assertEqual(hit, 255)
# assert that using pure types directly is faster
self.assertTrue(new_secs < orig_secs)
if __name__ == '__main__':
unittest.main()