Locked History Actions

HowTo/PythonProfiling

How To Profile a Python Script

Run the program using cProfile to log data to profile.out as it runs:

python -m cProfile -o profile.out <myprogram> <myargs> ...

Load the profile data in an interactive python session:

import pstats
p = pstats.Stats('profile.out')

Get a list of the top ten routines where the time is being spent:

p.sort_stats('time').print_stats(10)

More details here.