compareCython

%cython cdef double cf(double x): return x**2 - 2 * x def cintegre(double a, double b, int N): cdef int i cdef double s, dx s = 0 dx = (b - a) / N for i from 0 <= i < N: s += cf(a + i*dx) return s*dx 
timeit('cintegre(0.,2.,2^20)') 
       
125 loops, best of 3: 4.84 ms per loop