Azitech

Azimout's Linux weblog

Profiling your Python programs

with one comment

cProfile is written in C (low overhead) and included in the Python standard library: http://docs.python.org/library/profile.html

sudo aptitude install python-profiler and then run python -m cProfile -s cumulative your_code.py

If you want per-line statistics of your code, download the line_profiler: http://pypi.python.org/pypi/line_profiler

Get the .tar.gz, as the mercurial tree FTBFS (gcc: _line_profiler.c: No such file or directory), extract and run sudo python setup.py install

(If you get a gcc error about not finding Python.h, you need to install python-dev)

Then run kernprof.py your_program.py and then python -m line_profiler your_program.py.prof

Advertisements

Written by azimout

28/02/2011 at 16:34

Posted in Howto

One Response

Subscribe to comments with RSS.

  1. […] written before about ways to profile your Python code. Here’s also a good guide with tips on Python performance […]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: