[Pythonmac-SIG] Speed up Python on the Mac?
Christopher Barker
Chris.Barker at noaa.gov
Tue Dec 6 19:08:26 CET 2005
Louis Pecora wrote:
>>Although this will not help you know, I have been told, Pycho
>><http://psyco.sourceforge.net/> will run on the Intel Chip.
> Thanks for the tips, Brian. Wish I had that Intel Chip Mac Powerbook
> now. :-)
Even so, Psyco doesn't understand NumPy arrays, which I hope you're
already using.
Essentially, you are right that you need to write some of your code in
C, and that it's quite tedious to do it be hand. There are a number of
tools that make it easier however. Here's my assessment, but I haven't
actually used all of these:
SWIG -- Automatically creates wrapper for existing C/C++ code. A good
choice if you are working with a n existing library, particularly if
that library is under development (i.e. wxPython)
f2py -- similar to SWIG, but for Fortran code. Understands NumPy arrays.
A good option if you have Fortran code you want to use, or like writing
Fortran
SIP: similar to SWIG, used for PyQT, that's all I know.
Boost::Python -- C++ wrappers for the basic Python data types, handles
reference counting etc. for you. I think there are some wrappers for
NumPy arrays as well. A good choice if you want to write custom
extension code in C++
Pyrex -- A python-like language for writing C extensions. It makes it
very easy to write what is essentially a mixture of Python and C, with
Python syntax. Easy to call C functions. Probably the easiest way to
write custom extensions. Can work with NumPy arrays, but only at the C
level -- working with a pointer to the data.
Psyco -- automatically translates pieces of your runtime code into
machine language. Understands standard python data types, including the
array.array type. Does not know about NumPy arrays (darn!). Can make
major speed improvements for numeric code, but only if you use
array.array or regular old lists and tuples. It's extremely easy to use,
so why not try it on your code? Only available for x86 processors.
Weave.Blitz -- From the SciPy project. Automatically, and on the fly,
translates and compiles individual NumPy expressions into C++ using the
Blitz++ library. Probably the easiest way to speed up small sections of
code.
Cxx -- kind of like Boost::Python. Is it still being maintained?
Have I got them all? I hope this helps.
Make sure to check out the SciPy docs, there is discussion of optimizing
numerical code in various places there.
-Chris
--
Christopher Barker, Ph.D.
Oceanographer
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker at noaa.gov
More information about the Pythonmac-SIG
mailing list