O'Reilly logo

Python High Performance Programming by Gabriele Lanaro

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Finding bottlenecks with cProfile

After assessing the execution time of the program we are ready to identify the parts of the code that need performance tuning. Those parts are typically quite small, compared to the size of the program.

Historically, there are three different profiling modules in Python's standard library:

  • The profile module: This module is written in pure Python and adds a significant overhead to the program execution. Its presence in the standard library is due mainly to its extendibility.
  • The hotshot module: A C module designed to minimize the profiling overhead. Its use is not recommended by the Python community and it is not available in Python 3.
  • The cProfile module: The main profiling module, with an interface similar to

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required