Performance of Python 3
stefan_ml at behnel.de
Mon Mar 2 09:02:27 CET 2009
Isaac Gouy wrote:
> On Mar 1, 11:24 am, Stefan Behnel wrote:
>> Isaac Gouy wrote:
>>> On Mar 1, 8:10 am, Stefan Behnel wrote:
>>>> As long as that gives you improvements of
>>>> 100-1000 times almost for free, I wouldn't bother too much with changing
>>>> the platform just because someone shows me benchmark results of some code
>>>> that I absolutely don't need in my daily work.
>>> What examples do you have of 1000x improvement?
>> We hear that from time to time on the Cython mailing list. Here's a recent
>> example of a user who reported an 80 times speed-up before we helped in
>> getting the code straight, which brought another factor of 20.
>> Speed-ups in the order of several hundred times are not uncommon for
>> computing intensive tasks and large data sets when you move from Python to
>> Cython, as it generates very optimised C code.
> "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.
More information about the Python-list