Profiling Python Code

Figure out the bottlenecks in your Python scripts.

Run Your Code with cProfile

python -m cProfile -o my_output.cprof

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 ncalls
  • cumtime: total time spent in this and all subfunctions
  • percall: quotient of cumtime divided by primitive calls
Nicholas Nadeau, Ph.D., P.Eng.
Nicholas Nadeau, Ph.D., P.Eng.
Project Director

Nicholas Nadeau is the project director at Halodi Robotics, leading their mission of bringing safe and capable humanoid robots to everyone.