|
13 | 13 | import timeit
|
14 | 14 | import numpy
|
15 | 15 |
|
16 |
| -array_size = 1000*1000 |
| 16 | +array_size = 5_000_000 |
17 | 17 | iterations = 10
|
18 | 18 |
|
19 | 19 | numpy_ttime = []
|
|
23 | 23 | numexpr_sttime = []
|
24 | 24 | numexpr_nttime = []
|
25 | 25 |
|
| 26 | + |
26 | 27 | def compare_times(expr, nexpr):
|
27 | 28 | global numpy_ttime
|
28 | 29 | global numpy_sttime
|
@@ -64,15 +65,15 @@ def compare_times(expr, nexpr):
|
64 | 65 | numexpr_stime = round(numexpr_timer.timeit(number=iterations), 4)
|
65 | 66 | numexpr_sttime.append(numexpr_stime)
|
66 | 67 | print("numexpr strided:", numexpr_stime/iterations, end=" ")
|
67 |
| - print("Speed-up of numexpr strided over numpy:", \ |
| 68 | + print("Speed-up of numexpr strided over numpy:", |
68 | 69 | round(numpy_stime/numexpr_stime, 4))
|
69 | 70 |
|
70 | 71 | evalexpr = 'evaluate("%s", optimization="aggressive")' % expr
|
71 | 72 | numexpr_timer = timeit.Timer(evalexpr, setup_unaligned)
|
72 | 73 | numexpr_ntime = round(numexpr_timer.timeit(number=iterations), 4)
|
73 | 74 | numexpr_nttime.append(numexpr_ntime)
|
74 | 75 | print("numexpr unaligned:", numexpr_ntime/iterations, end=" ")
|
75 |
| - print("Speed-up of numexpr unaligned over numpy:", \ |
| 76 | + print("Speed-up of numexpr unaligned over numpy:", |
76 | 77 | round(numpy_ntime/numexpr_ntime, 4))
|
77 | 78 |
|
78 | 79 |
|
@@ -113,7 +114,7 @@ def compare_times(expr, nexpr):
|
113 | 114 | expressions.append('sqrt(i2**2 + f3**2) > 1')
|
114 | 115 | expressions.append('(i2>2) | ((f3**2>3) & ~(i2*f3<2))')
|
115 | 116 |
|
116 |
| -def compare(expression=False): |
| 117 | +def compare(expression=None): |
117 | 118 | if expression:
|
118 | 119 | compare_times(expression, 1)
|
119 | 120 | sys.exit(0)
|
|
0 commit comments