63 points · by suhail · 16y ago · 33 comments
There are many options to speed up your Python code by ~50 times effortlessly. See my blog posts:
http://docs.python.org/library/profile.html http://wiki.python.org/moin/PythonSpeed/PerformanceTips
As an aside some simple coding changes will allow Psyco to do much of the by hand optimisations that Cython gives you. Not all and it is easy for another coder to come along and ruin everything. All it takes is some understanding of how Psyco performs its magic.
http://kayhayen24x7.homelinux.org/blog/2010/09/nuitka-releas...
Let me introduce you to Cython.
As the author shows, writing a python c extension is fundamentally easy which is why Python has such a huge ecosystem of them to begin with.
If dependency for distribution is an issue, you can just include the generated C code (as we do in numpy and scipy, as a matter of fact). Also, cython can generate both python 2 and 3 compatible code.
In fact, if you set up the gateway interface to your C code cleanly, you can have the same C code callable directly from (e.g.) Matlab via the "mex" mechanism.
http://www.artima.com/weblogs/viewpost.jsp?thread=95863
"But even if I find the cause of the leak, I may not be able to plug it. M2Crypto is written using SWIG, which contains lots of obfuscated code and doesn't exactly give me a warm fuzzy feeling that it's always doing the reference counting correctly."
I prefer a clean handwritten C extension any day. There is a lot of repetitive work involved, but most of that is really just copy&paste, so it tends to go quickly.
This method is so productive it always surprises me how quickly things get done!