File tree Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change 3
3
from argparse import ArgumentParser
4
4
import array_sum
5
5
import numpy as np
6
+ import pyximport
6
7
import timeit
7
8
9
+ pyximport .install ()
10
+ import array_sum_pure
8
11
9
12
def py_sum (a ):
10
13
total = 0.0
@@ -15,17 +18,17 @@ def py_sum(a):
15
18
16
19
if __name__ == '__main__' :
17
20
arg_parser = ArgumentParser (description = 'compute array sum using '
18
- 'np.sum, cython and python' )
21
+ 'np.sum, cython pyx, cython pure and python' )
19
22
arg_parser .add_argument ('--n' , type = int , default = 10_000 ,
20
23
help = 'size (nxn array)' )
21
24
arg_parser .add_argument ('--iter' , type = int , default = 10 ,
22
25
help = 'number of iterations' )
23
26
options = arg_parser .parse_args ()
24
27
a = np .ones ((options .n , options .n ))
25
- for func in [array_sum .array_sum , np .sum , py_sum ]:
28
+ for func in [array_sum .array_sum , array_sum_pure . array_sum , np .sum , py_sum ]:
26
29
total = 0.0
27
30
start_time = timeit .default_timer ()
28
31
for iter_nr in range (options .iter ):
29
32
total += func (a )
30
33
total_time = timeit .default_timer () - start_time
31
- print (f'{ func .__name__ :s} : { total_time :.6f} s ({ total } )' )
34
+ print (f'{ func .__qualname__ :s} : { total_time :.6f} s ({ total } )' )
You can’t perform that action at this time.
0 commit comments