Skip to content

Commit b09f5af

Browse files
committed
Add timing for pure Python Cython implementation
1 parent 2d95302 commit b09f5af

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

source-code/cython/Numpy/compute_sums.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
from argparse import ArgumentParser
44
import array_sum
55
import numpy as np
6+
import pyximport
67
import timeit
78

9+
pyximport.install()
10+
import array_sum_pure
811

912
def py_sum(a):
1013
total = 0.0
@@ -15,17 +18,17 @@ def py_sum(a):
1518

1619
if __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})')

0 commit comments

Comments
 (0)