Posted Feb 28, 2007 1:38 UTC (Wed) by drag
In reply to: garbage-collecting VMs
Parent article: Ruby Performance (Linux Journal)
Maybe something like Pyrex?
As you probably know python is a slow language. However it is used in lots of places that demand very high performance from programs.
How you deal with this, as I am told, is that you write the program you want to do in python. Use it and profile it. If it doesn't give acceptable performance then find the portiosn of the code that are slow and them figure out optimizations for it.
If you optimize as much as you can in python and it's still slow then you take your now-highly optimized python code and translate it to a C which you then compile and import into your python program as a module.
The key to making it all work is to write the program using generic code and _then_ identify bottlenecks (instead of speculating ahead of time), then refactor the code until it's no longer possible to get better performance _then_ rewrite it in a lower level language. That way you end up with a working program first (abiet slow) and then spend your time as wisely as possible to make it fast after some more realworld-ish experiance and testing.
Thats the theory anyways. How well it works out is my guess.
Well one of the major downsides to this approach is that although writing Python programs is easy, writing python extensions in C is not.
It requires a significant portion of boiler plate code and can be tricky to make things 'python-ish'.
So that is why Pyrex is invented. You can take straight python code (with some caveats), compile it with pyrex and get compiled python. Not realy that much faster, but the key is that you can then mix and match C code with python code... Allow them to intermingle in that python module your making freely and without all the boilerplate cruft.
Often times you can end up with superior results then trying to write in pure C or import a C/C++ library using bindings and such.
The some it up as: "Pyrex is Python with C data types."
to post comments)