[Pyrex] Re: Pyrex

Greg Ewing greg.ewing at canterbury.ac.nz
Fri Oct 21 01:43:11 CEST 2005

P.Saffrey wrote:

> What is the benefit of writing modules in Pyrex and compiling them as C,
> rather than simply writing them in Python? Can you show me some examples
> of this giving a significant speed increase?

Pyrex is not intended to speed up pure Python code. You
might get a moderate speed increase this way, but nothing
spectacular. I haven't done any measurements, but going
by the results of an earlier Python-to-C compiler project,
you can't expect more than 2 or 3 times, maybe less.

The ways to get substantial speed improvements using Pyrex are:

1) Write Pyrex code containing C operations, which will
execute much faster than equivalent Python operations.
E.g. the primes.pyx example runs about 200 times faster
than the Python version on my system.

2) Use Pyrex to wrap an existing library implemented in
a compiled language such as C.

A possible reason to use Pyrex on pure Python code might
be to render it more resistant to reverse engineering.

Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury,	   | A citizen of NewZealandCorp, a	  |
Christchurch, New Zealand	   | wholly-owned subsidiary of USA Inc.  |
greg.ewing at canterbury.ac.nz	   +--------------------------------------+

More information about the Pyrex mailing list