Stefan Behnel, 26.05.2010 13:23:
> I got sum(genexp) working in cython-closures (not pushed yet), so here are
> some timings. The Cython code (of this pretty bad benchmark) is:
>
> def return_range_sum(int N):
> return sum(i for i in range(N))
>
> timeit "sum(i for i in xrange(10000))"
> 1000 loops, best of 3: 584 usec per loop
>
> timeit "return_range_sum(10000)"
> 1000 loops, best of 3: 235 usec per loop
>
> Note that the generated C code runs the loop in C but does the addition in
> Python objects.
... and the obvious little update on the last sentence:
def range_sum_typed(int N):
cdef int result = sum(i for i in range(N))
return result
timeit "range_sum_typed(10000)"
100000 loops, best of 3: 2 usec per loop
Now, that's better. ;)
Stefan
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev