Hi all,

I only recently found out that the mailing list had shifted, so I hope
my message reaches you this time!

On the current development version of Cython, the attached script
makes Cython go into an infinite loop, but let's hope that's just on
my machine.

Regards
Stéfan

---------- Forwarded message ----------
Date: 2011/8/21
Subject: Speed of cython.compile
To: [email protected]

Hi all,

I am trying to illustrate Cython's pure mode for a tutorial, and made
up a quick fibonacci example (attached).  But when I run the timings,
I get:

Cython: 5.515417099
Python: 0.123511791229

When I compile the module by hand (.pyx -> .c -> .so) the timings are perfect:

Cython: 0.0394787788391
Python: 0.119538068771

Any idea what's going on?  I cleared ~/.cython just to be sure, but
that didn't help.

Regards
Stéfan
import cython
from timeit import timeit

@cython.compile
@cython.locals(n=int)
def fib(n):
    f = cython.declare(list, [1, 1])
    i = cython.declare(int)
    for i in range(n - 2):
        f.append(f[-1] + f[-2])
    
    return f

fib(5)

print 'Cython:', timeit('fib(500)', setup="from __main__ import fib", number=1000)

def fib_py(n):
    f = [1, 1]
    for i in range(n - 2):
        f.append(f[-1] + f[-2])
    
    return f

print 'Python:', timeit('fib_py(500)', setup="from __main__ import fib_py", number=1000)

_______________________________________________
cython-devel mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cython-devel

Reply via email to