[Tutor] Compiling Python to Native Machine Code
Danny Yoo
dyoo at hkn.eecs.berkeley.edu
Tue Sep 2 04:36:50 EDT 2003
On Tue, 2 Sep 2003, Marc Barry wrote:
> Is it possible to compile Python directly to native machine code? The
> reason I ask is because I am using Python to do some pretty intensive
> simulations that take anywhere between 10 minutes and a few hours to
> run. I assume that if I could compile it directly to machine code that
> this may speed up my simulation times.
Hi Mark,
At the moment, no. You may be able to get some substantial performance by
using Psyco, though:
http://psyco.sourceforge.net/
If your code is particularly algorithmic in nature, Psyco might do wonders
for it.
If you can identify which parts of code are performance hogs, we have a
few options. For example, it might be possible to recode those
performance-critical pieces in another language --- like C or OCaml ---
and bind those recoded pieces to Python.
If you want to take this route, there's good prior work that's gone into
this. *grin* People have written several popular tools to help do this
"extending"; you may want to look into Scientific Python's "weave" module:
http://www.scipy.org/
as well as SWIG:
http://www.swig.org/
> Does anyone have any experience with doing this? Would there be any
> significant gains?
It really depends on the algorithms that you are using. Do you mind
showing us a sample of the kind of calculations you're doing? And do you
have a "profile" of your application? Profiles can help pinpoint busy
areas of the code. Here's documentation to Python's profiler:
http://www.python.org/doc/lib/profile.html
Good luck to you!
More information about the Tutor
mailing list