Optimizing python with Cython(korokithakis.net)
korokithakis.net
Optimizing python with Cython
http://www.korokithakis.net/node/109
4 comments
Worth checking out pysco as well http://psyco.sourceforge.net/
Though in practice I find that if performance really matters using numpy or writing a C extension module usually works out the best.
Though in practice I find that if performance really matters using numpy or writing a C extension module usually works out the best.
I like psyco simply because all you have to do is import the module and do `psyco.full()` to get an idea how well it's going to work with your code. Once I feel like I've gotten the most I can possibly get out of algorithmic and data structure optimization, psyco is almost always my next stop for further speed. Often, importing and activating psyco is all the optimization I end up needing.
I would like to note though, that psyco development has been stopped for a couple years, and probably won't continue (unless a new developer thinks there's a future and takes it over). Further development is going into pypy.
Also, it can't run on 64-bit machines. If you want to run it on OS/X 10.6, you need to build your own 32 bit python.
Also, it can't run on 64-bit machines. If you want to run it on OS/X 10.6, you need to build your own 32 bit python.
Does this really make sense, instead of just coding your application in C/C++ or even Go? Seems like you have to rape your Python source code pretty totally.
Or how about implementing the performance-sensitive parts as native C modules for Python.
Or how about implementing the performance-sensitive parts as native C modules for Python.
This is actually one of the ways people write C modules for python. It is a Python -> C translator tool (which the linked article doesn't make very clear).
I myself prefer sip or weave, but this is also just another way to write C that is tied into python.
I myself prefer sip or weave, but this is also just another way to write C that is tied into python.
I had similar speed issues in an evolutionary computing class last semester. I took it as an opportunity to learn Haskell and Scala, and noticed that in addition to getting dramatic speedups, I also had a lot more fun writing the code in the first place.
As is always the case with optimizations, a good algorithm usually goes a lot further than highly optimized, low level code.