Tuesday, May 10, 2011

How to use Python Profiler

The simplest way to profile a python program is to run:

python -m cProfile --sort cumulative youprogram.py

The other sorting options are:

callscall count
cumulativecumulative time
filefile name
modulefile name
pcallsprimitive call count
lineline number
namefunction name
nflname/file/line
stdnamestandard name
timeinternal time

The profiling results are dumped to console. Use

python -m cProfile --sort cumulative youprogram.py > profile.txt

to forward all console output to profile.txt file.

1 comment:

paurullan said...

Thank you, this was very useful.