In [1]:
import setuptools
%load_ext cython

In [2]:
import numpy as np

In [3]:
%%cython
def cythonfib(int n):
    cdef int a,b,i
    a, b = 0, 1
    for i in range(n):
        a, b = a+b , a
    return a

In [4]:
def pythonfib(n):
    a, b = 0, 1
    for i in range(n):
        a, b = a+b , a
    return a

In [5]:
%timeit cythonfib (4)


The slowest run took 20.29 times longer than the fastest. This could mean that an intermediate result is being cached 
10000000 loops, best of 3: 52.2 ns per loop

In [6]:
%timeit pythonfib (4)


1000000 loops, best of 3: 646 ns per loop

In [24]:
%%cython
from libc.math cimport sin
def sinefunc(float b):
    cdef float a
    a = sin(b)
    return a

In [27]:
import numpy as np
a = sinefunc(np.pi)
a


Out[27]:
-8.742277657347586e-08