Cython taking more time than regular Python
Peter Otten
__peter__ at web.de
Tue Sep 20 03:44:29 EDT 2016
Stefan Behnel wrote:
> 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.
Is that optimization useful in an actual program or just a way to cheat in
benchmarks?
More information about the Python-list
mailing list