I use it once in a while, but I forget how to use it soon.
Take a profile in the program or on the interpreter. If you want to take a profile of a function with some_command:
import cProfile
cProfile.run('some_command()', 'spam.prf')
Take a profile from the command line. If you want to profile the execution of a file called do.py:
$ python -m stats -o spam.prf do.py
Each proifle is stored in spam.prf.
View profile results.
$ python -m pstats spam.prf
spam.prf% stats
Recommended Posts