Profiling
When we talk about profiling our code, what we intend to do is measure some key attributes about our programs, such as how much memory they use, the time complexity of our programs, or the usage of particular instructions. It's a vital tool in a programmer's arsenal when it comes to squeezing the highest performance out of their systems.
Profiling, typically, uses a technique called Dynamic program analysis to achieve its measurements, and this involves running our programs on a real or virtual processor. The technique goes all the way back to IBM/360 and IBM/370 platforms in the early 1970s.
cProfile
cProfile is a C-based module that comes as part of Python as standard. We can use it to understand the following characteristics of our code:
ncalls:
This is the number of times a line/function is called throughout the execution of our program.tottime
: This is the total time that the line or function took to execute.percall
: This is the total time divided by the number of calls.cumtime...