Home » » cython function in ipython

cython function in ipython

cython function in ipython

%load_ext cythonmagic

In [4]: %%cython
   ...: def fib(int n):
   ...:         cdef int a,b,i
   ...:         a,b=1,1
   ...:         for i in range(n):
   ...:                 a, b = a+b, a
   ...:         return a
   ...:

Just a simple rewrite, the cython function is 100X faster than the python one. 

0 Comments:

Popular Posts