The other answers have already explained how you were just compiling the Cython code, not executing it. However, I thought that you might want to know how much faster Cython can make your code. When I compiled the code you have (though I ran the function from from a different module) with distutils
, I got very marginal speed gains over straight Python – about 1%. However, when I added a few small changes to your code:
def test(long long value):
cdef long long i
cdef long long z
for i in xrange(value):
z = i**2
if(i==1000000):
print i
if z < i:
print "yes"
and compiled it, I got the following times:
- Pure Python code: 20.4553578737 seconds
- Cython code: 0.199339860234 seconds
That’s a 100× speed-up. Not too shabby.