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 33from argparse import ArgumentParser
44import array_sum
55import numpy as np
6+ import pyximport
67import timeit
78
9+ pyximport .install ()
10+ import array_sum_pure
811
912def py_sum (a ):
1013 total = 0.0
@@ -15,17 +18,17 @@ def py_sum(a):
1518
1619if __name__ == '__main__' :
1720 arg_parser = ArgumentParser (description = 'compute array sum using '
18- 'np.sum, cython and python' )
21+ 'np.sum, cython pyx, cython pure and python' )
1922 arg_parser .add_argument ('--n' , type = int , default = 10_000 ,
2023 help = 'size (nxn array)' )
2124 arg_parser .add_argument ('--iter' , type = int , default = 10 ,
2225 help = 'number of iterations' )
2326 options = arg_parser .parse_args ()
2427 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 ]:
2629 total = 0.0
2730 start_time = timeit .default_timer ()
2831 for iter_nr in range (options .iter ):
2932 total += func (a )
3033 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