Profiling Python
There are a few different ways to profile a Python application. Profiling means having the application run while keeping track of several different parameters, such as the number of times a function is called and the amount of time spent inside it. Profiling can help us find the bottlenecks in our application, so that we can improve only what is really slowing us down.
If you take a look at the profiling section in the standard library official documentation, you will see that there are a couple of different implementations of the same profiling interface—profile
and cProfile
:
cProfile
is recommended for most users, it's a C extension with reasonable overhead that makes it suitable for profiling long-running programsprofile
is a pure Python module whose interface is imitated bycProfile
, but which adds significant overhead to profiled programs
This interface does determinist profiling, which means that all function calls, function returns, and exception events are monitored...