My program is slow, and I don’t know what it’s doing!
Don’t do this, and it will be fast!
Understand where time is spend during execution
cProfile
python -m cProfile -o cprofile.dat <PROGRAM>.py
sudo apt install austin
austin python <PROGRAM>.py
Works with profiles generated by cProfile
.
gprof2dot
$ sudo apt-get install graphviz
$ git clone https://github.com/jrfonseca/gprof2dot
$ ln -s "$PWD"/gprof2dot/gprof2dot.py ~/bin
$ cd $PROJECT_DIR
$ gprof2dot.py -f pstats cprofile.dat | dot -Tsvg -o callgraph.svg
(pycallgraph is a python specific alternative)
Find this presentation at karie.eu/python_profiling
..and soon in our wiki ;)
Weekly nice to know