-
Notifications
You must be signed in to change notification settings - Fork 13
/
speedtests.py
92 lines (73 loc) · 2.81 KB
/
speedtests.py
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import unittest
from datetime import datetime
import fecfile
from collections import Counter
def speed_test(filepath):
print("+++++\nRunning speed test on %s" % filepath)
formtypecount = Counter()
start = datetime.now()
parsed = {}
with open(filepath) as file:
linecount = 0
version = None
for line in file:
linecount += 1
if version is None:
results = fecfile.parse_header(line)
version = results[1]
else:
parsed = fecfile.parse_line(line, version)
if not parsed:
print("** not parsed %s" % line)
else:
# count the form type, if given
try:
formtypecount.update({parsed['form_type'].upper(): 1})
except KeyError:
continue
end = datetime.now()
print("+++++\nResults:")
print("\tRan %s rows in %s" % (sum(formtypecount.values()), end-start))
print("\tTotal rows processed = %s" % formtypecount)
def from_file_speed(filepath, options={}):
print('++++\nRunning speed test on {0} with {1}'.format(filepath, options))
start = datetime.now()
parsed = fecfile.from_file(filepath, options)
end = datetime.now()
num_itemizations = 0
for itemization_type in parsed['itemizations'].keys():
num_itemizations += len(parsed['itemizations'][itemization_type])
print('parsed file with {0} itemizations in {1}'.format(
num_itemizations,
end - start,
))
class SpeedTestSmallFile(unittest.TestCase):
def test_simple(self):
speed_test('test-data/1229017.fec')
def test_from_file(self):
a_filter = {'filter_itemizations': ['SB']}
from_file_speed('test-data/1229017.fec', options=a_filter)
class SpeedTestSmallOldFile(unittest.TestCase):
def test_simple(self):
speed_test('test-data/27789.fec')
def test_from_file(self):
a_filter = {'filter_itemizations': ['SB']}
from_file_speed('test-data/27789.fec', options=a_filter)
class SpeedTestMediumRecentFile(unittest.TestCase):
def test_simple(self):
speed_test('test-data/1162172.fec')
def test_from_file(self):
a_filter = {'filter_itemizations': ['SD']}
from_file_speed('test-data/1162172.fec', options=a_filter)
if __name__ == '__main__':
regular_tests = unittest.TestSuite([
SpeedTestSmallFile('test_simple'),
SpeedTestSmallOldFile('test_simple'),
SpeedTestMediumRecentFile('test_simple'),
])
from_file_tests = unittest.TestSuite([
SpeedTestSmallFile('test_from_file'),
SpeedTestSmallOldFile('test_from_file'),
SpeedTestMediumRecentFile('test_from_file'),
])
unittest.TextTestRunner().run(from_file_tests)