Cython taking more time than regular Python

Stefan Behnel stefan_ml at behnel.de
Tue Sep 20 01:27:34 EDT 2016


Peter Otten schrieb am 19.09.2016 um 14:55:
> In [7]: %%cython
> def omega(int n):
>     cdef long i
>     cdef long result = 0
>     for i in range(n): result += i
>     return result
>    ...: 
> 
> In [8]: %timeit omega(100000)
> 10000 loops, best of 3: 91.6 µs per loop

Note that this is the worst benchmark ever. Any non-dump C compiler will
happily apply Young Gauß and calculate the result in constant time.

Stefan





More information about the Python-list mailing list