Isaac said:
"Now only the def line and the return line are using Python..." ;-)
So? I did see your smiley, but I hope you are not trying to make a point
here. If you look at the code (especially in this case, it might be more
C-ish in others), you will see that it's Python. It just gets translated to
very fast C code. Cython even has a "pure Python" mode where you can let
your code run in ordinary Python and have Cython compile it if you feel
like it. That gives you the best of both worlds: readable, easy to maintain
code, that you can compile to C speed when you need high performance.
Coming back to the original topic of this thread, when I look at the code
examples that are compared here, I wouldn't be surprised if Cython could
compile them to a faster executable straight away, without modification.
Just install Cython 0.11 (which is close to release) and add
import pyximport; pyximport.install(pyimport=True)
before importing the benchmarked module. If you want more performance than
what plain compilation gives you by itself, just add a few type
declarations. You can use Python decorators for that, if you prefer keeping
a standard Python program.
Stefan