Profiling Python Code
Figure out the bottlenecks in your Python scripts.
Run Your Code with cProfile
python -m cProfile -o my_output.cprof my_script.py
Visualize Your Code’s Execution
# visualize with pyprof2calltree
pip install pyprof2calltree
pyprof2calltree -k -i my_output.cprof
# visualize with pyprof2calltree
pip install snakeviz
snakeviz my_output.cprof
ncalls
: number of calls,tottime
: total time spent in the given function (excluding time made in calls to sub-functions)percall
: quotient of tottime divided by ncallscumtime
: total time spent in this and all subfunctionspercall
: quotient of cumtime divided by primitive calls