I am searching for ways to get a better python performance. For example: fib.py
import datetime
def fibonacci(n):
a,b = 1,1
for i in range(n-1):
a,b = b,a+b
return a
t1 = datetime.datetime.now()
fibonacci(590000)
t2 = datetime.datetime.now()
t=(t2-t1).total_seconds()
print("Time:",t)
took 4.337s.
I also wrote a extension module with a setup.py file which generates a fib.pyd file which can then be included. (Compiled with distutils)
from distutils.core import setup
from Cython.Build import cythonize
setup (ext_modules = cythonize("fib.pyx"))
It took 4.275s.
Am I doing it wrong, or why is Cython not improving the runtime?
(Numba took 1.03s)
Any help/similar experience is appreciated.