Skip to content

Commit d6199bf

Browse files
committed
Adding loop test code.
1 parent e823ef7 commit d6199bf

File tree

3 files changed

+193
-0
lines changed

3 files changed

+193
-0
lines changed

loop-test/loop-test.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env python
2+
3+
import sys
4+
import csv
5+
import timeit
6+
7+
MICRO = 10 ** 6 # how many microseconds in a sec
8+
9+
def noop(*args):
10+
pass
11+
12+
def main():
13+
test_runs = 3 # 10 ** 3
14+
test_range = 10
15+
test_count = 30
16+
w = csv.writer(sys.stdout)
17+
styles = ['map', 'list_comp', 'loop']
18+
w.writerow(['test', ''] + styles)
19+
for t in range(6):
20+
for i in range(test_range):
21+
sr = {}
22+
for style in styles:
23+
tr = timeit.timeit(
24+
"t()",
25+
"from tests import test%(t)s as test_creator; t = test_creator('%(style)s', %(i)s)" % { 'style': style, 'i': (i+1)*test_count, 't': t+1 },
26+
number = test_runs,
27+
)
28+
sr[style] = tr
29+
w.writerow(['test%s'%(t+1), str(i+1)] + ['%.3f' % (sr[s] * MICRO / test_runs) for s in styles])
30+
sys.stdout.flush()
31+
32+
if __name__ == '__main__':
33+
main()

loop-test/results/results.csv

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
test,,map,list_comp,loop
2+
test1,1,7.073,7.312,6.040
3+
test1,2,11.047,13.272,11.047
4+
test1,3,15.656,18.994,18.676
5+
test1,4,20.266,24.319,20.981
6+
test1,5,25.034,30.041,25.988
7+
test1,6,30.041,36.001,30.994
8+
test1,7,37.352,41.008,36.319
9+
test1,8,39.657,47.048,41.008
10+
test1,9,44.346,51.975,45.935
11+
test1,10,49.273,57.697,51.022
12+
test2,1,287.930,185.013,173.648
13+
test2,2,1090.686,706.355,662.645
14+
test2,3,2418.280,1580.636,1471.996
15+
test2,4,4273.335,2792.358,2616.962
16+
test2,5,6728.013,4393.339,4031.022
17+
test2,6,9556.055,6235.361,5791.028
18+
test2,7,12981.335,8519.729,7884.979
19+
test2,8,17022.292,11236.032,10465.701
20+
test2,9,22599.379,14330.705,12998.343
21+
test2,10,26715.040,17330.329,16053.677
22+
test3,1,10192.633,6268.978,5851.348
23+
test3,2,78685.045,50862.630,46212.355
24+
test3,3,262993.018,172087.669,156613.668
25+
test3,4,640459.379,403170.347,371235.609
26+
test3,5,1199440.002,783643.961,719916.344
27+
test3,6,2079129.060,1403111.935,1242798.646
28+
test3,7,3284796.317,2186232.011,1971901.019
29+
test3,8,4893622.398,3234438.976,2952066.024
30+
test3,9,6955078.999,4623496.294,4196753.661
31+
test3,10,9745362.282,6303009.033,5749389.966
32+
test4,1,6.994,7.629,10.729
33+
test4,2,11.047,13.351,18.279
34+
test4,3,15.736,18.994,26.385
35+
test4,4,20.663,24.716,34.650
36+
test4,5,24.954,29.961,42.995
37+
test4,6,30.041,36.319,51.339
38+
test4,7,34.332,41.326,59.366
39+
test4,8,39.339,46.968,67.711
40+
test4,9,46.651,52.611,75.340
41+
test4,10,49.035,58.015,83.367
42+
test5,1,285.069,185.966,269.731
43+
test5,2,1083.612,715.017,1042.684
44+
test5,3,2417.644,1590.331,2313.375
45+
test5,4,4258.951,2799.670,4119.396
46+
test5,5,6670.316,4387.299,6473.303
47+
test5,6,9569.327,6286.383,9232.283
48+
test5,7,12976.964,8535.385,12587.706
49+
test5,8,16931.375,11138.042,16382.694
50+
test5,9,21411.339,14088.710,20821.969
51+
test5,10,26506.344,17352.343,25577.386
52+
test6,1,9703.000,6453.991,8619.308
53+
test6,2,74633.042,51236.312,68336.964
54+
test6,3,248765.310,171385.050,230781.317
55+
test6,4,584289.312,407492.956,548589.309
56+
test6,5,1140658.696,795018.673,1079078.674
57+
test6,6,1970503.966,1414717.038,1884580.294
58+
test6,7,3117335.399,2173988.342,2917993.943
59+
test6,8,4658020.655,3324104.309,4449507.634
60+
test6,9,6628776.709,4704991.738,6361190.637
61+
test6,10,9101038.694,6487662.951,8635653.337

loop-test/tests.py

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
def noop(*args):
2+
pass
3+
4+
def test1(style, count):
5+
x = range(count)
6+
if style == 'map':
7+
def test():
8+
map(noop, x)
9+
if style == 'list_comp':
10+
def test():
11+
[noop(a) for a in x]
12+
elif style == 'loop':
13+
def test():
14+
for a in x:
15+
noop(a)
16+
return test
17+
18+
19+
def test2(style, count):
20+
x = range(count)
21+
if style == 'map':
22+
def test():
23+
map(lambda a: map(lambda b: noop(a,b), x), x)
24+
if style == 'list_comp':
25+
def test():
26+
[noop(a, b) for a in x for b in x]
27+
elif style == 'loop':
28+
def test():
29+
for a in x:
30+
for b in x:
31+
noop(a, b)
32+
return test
33+
34+
def test3(style, count):
35+
x = range(count)
36+
if style == 'map':
37+
def test():
38+
map(lambda a: map(lambda b: map(lambda c: noop(a,b,c), x), x), x)
39+
if style == 'list_comp':
40+
def test():
41+
[noop(a, b, c) for a in x for b in x for c in x]
42+
elif style == 'loop':
43+
def test():
44+
for a in x:
45+
for b in x:
46+
for c in x:
47+
noop(a, b, c)
48+
return test
49+
50+
def test4(style, count):
51+
x = range(count)
52+
if style == 'map':
53+
def test():
54+
return map(noop, x)
55+
if style == 'list_comp':
56+
def test():
57+
return [noop(a) for a in x]
58+
elif style == 'loop':
59+
def test():
60+
r = []
61+
for a in x:
62+
r.append(noop(a))
63+
return r
64+
return test
65+
66+
def test5(style, count):
67+
x = range(count)
68+
if style == 'map':
69+
def test():
70+
return map(lambda a: map(lambda b: noop(a,b), x), x)
71+
if style == 'list_comp':
72+
def test():
73+
return [noop(a, b) for a in x for b in x]
74+
elif style == 'loop':
75+
def test():
76+
r = []
77+
for a in x:
78+
for b in x:
79+
r.append(noop(a, b))
80+
return r
81+
return test
82+
83+
def test6(style, count):
84+
x = range(count)
85+
if style == 'map':
86+
def test():
87+
return map(lambda a: map(lambda b: map(lambda c: noop(a,b,c), x), x), x)
88+
if style == 'list_comp':
89+
def test():
90+
return [noop(a, b, c) for a in x for b in x for c in x]
91+
elif style == 'loop':
92+
def test():
93+
r = []
94+
for a in x:
95+
for b in x:
96+
for c in x:
97+
r.append(noop(a, b, c))
98+
return r
99+
return test

0 commit comments

Comments
 (0)