[BangPypers] Python performance

Noufal Ibrahim noufal at gmail.com
Tue Dec 22 09:11:35 CET 2009

On Tue, Dec 22, 2009 at 1:25 PM, Ramdas S <ramdaz at gmail.com> wrote:

> Dear all,
> I saw this doc and  a few other docs online.
> http://wiki.python.org/moin/PythonSpeed/PerformanceTips
> Are there any recommendations on how I can improve performances in case of
> I/O. I have a program that opens between 4 to 7 text files in memory to
> analyze data. It runs beautifully on some 100 odd lines of Python code, but
> its quite slow, sometimes taking a few more seconds than desired.
> Is there any generic tips out there?

You can get some performance out of manually reviewing the code. If it's a
first draft, there will probably be chances for improvement (caching,
removing recomputation etc.).

I haven't really tried/measured it but you can use the -O option to the
interpreter to optimise the generated bytecode a little.

If you're running on a 32 bit machine, it might make sense to use the psyco
JIT http://psyco.sourceforge.net/. I don't think it's maintained though
(Armin Rego has to moved to PyPy) and I don't know how much it will help you
with I/O bound apps.

Finally, use a profiler http://docs.python.org/library/profile.html to find
out where the hotspots are in your code and squeeze them a little. If you
find a place which is really killing performance, it might make sense to
sacrifice some portability and move it to C or something low level.


More information about the BangPypers mailing list