Ref:
http://notes-on-cython.readthedocs.io/en/latest/std_dev.htmlExample:
def pyStdDev(a):
mean = sum(a) / len(a)
return math.sqrt((sum(((x - mean)**2 for x in a)) / len(a)))
In summary:
================= ============ ================== =====================
Method Time (ms) Compared to Python Compared to Numpy
================= ============ ================== =====================
Pure Python 183 x1 x0.03
Numpy 5.97 x31 x1
Naive Cython 7.76 x24 x0.8
Optimised Cython 2.18 x84 x2.7
Cython calling C 2.22 x82 x2.7
================= ============ ================== =====================