-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtime_test.py
More file actions
41 lines (30 loc) · 1.06 KB
/
time_test.py
File metadata and controls
41 lines (30 loc) · 1.06 KB
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
import timeit
from lazy import APIResponse as LazyResp
from eager import APIResponse as EagerResp
def testLazyIteration():
resps = [LazyResp.fromKeys('Chinook', 'Album', i) for i in range(1, 10)]
albsWith10Tracks = []
for resp in resps:
if len(resp['Track']) >= 10:
albsWith10Tracks.append(resp)
def testEagerIteration():
resps = [EagerResp.fromKeys('Chinook', 'Album', i) for i in range(1, 10)]
albsWith10Tracks = []
for resp in resps:
if len(resp['Track']) >= 10:
albsWith10Tracks.append(resp)
def createLazy():
r = LazyResp.fromKeys('Chinook', 'Album', 1)
r['Track']
def createEager():
r = EagerResp.fromKeys('Chinook', 'Album', 1)
r['Track']
if __name__ == '__main__':
NUM_TRYS = 10
t = timeit.Timer(testLazyIteration)
lazyTime = t.timeit(NUM_TRYS)
print('Time for lazy: ', lazyTime)
t = timeit.Timer(testEagerIteration)
eagerTime = t.timeit(NUM_TRYS)
print('Time for eager: ', eagerTime)
print('Lazy was about', round(eagerTime/lazyTime), 'times faster!')