Pyrex - The speed of Python with the clarity of C?

Peter Hansen peter at engcorp.com
Fri May 21 12:29:27 EDT 2004


SeeBelow at SeeBelow.Nut wrote:

> I just read "about Pyrex" at
> http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/version/Doc/About.html
> 
> It seems that it is not compiled into machine code, as C would be, and
> therefore it does not offer the only valid reason for using C, which is
> for an increase in execution speed.  The word "speed" does not appear on
> the above web page.
> 
> Am I wrong about this?  Perhaps I don't understand how Pyrex works.

Look at the primes.pyx example.  There's a link just below it
(above the Language Details section) showing the C code it is
compiled to (and which is in turn compiled to machine code).  True,
there are many calls to the Python/C interface APIs, but there is
also "pure" C code in there.

For ultimate speed (barring assembly, of course, or dedicated
hardware), you probably still want a C extension or library, but
Pyrex is much simpler in many cases, and preserves the Pythonesque
syntax.

-Peter



More information about the Python-list mailing list