Cython taking more time than regular Python
Arshpreet Singh
arsh840 at gmail.com
Mon Sep 19 06:55:52 EDT 2016
Hope this is good place to ask question about Cython as well.
Following code of mine is taking 2.5 times more time than Native Python code:
%%cython
import numpy as np
a = np.array([])
def large_sum2(int num_range):
np.append(a,[i for i in xrange(num_range)])
return a.sum
%timeit large_sum2(100000)
10 loops, best of 3: 19 ms per loop
on the other side python takes much less time:
def large_sum(num_range):
return sum([i for i in xrange(num_range)])
%timeit large_sum(100000)
100 loops, best of 3: 7 ms per loop
More information about the Python-list
mailing list