Identifying the bottlenecks
In the previous section, we saw how a different choice of input parameters degrades the application runtime. Now, we need some way to accurately measure the execution time and find out the performance bottlenecks or the time consuming blocks of the code.
Measuring the execution time
Let's start by monitoring the time taken by the application. To do this, we will use Python's built-in time
module. The time.perf_counter
function is a performance counter that returns a clock with the highest available resolution. This function can be used to determine the time interval or the system-wide time difference between the two consecutive calls to the function.
Tip
The time.perf_counter
function is available in Python versions 3.3 onwards. If you have an older version of Python (for example, version 2.7), use time.clock()
instead. On Unix, time.clock()
returns a floating point number within seconds that represents the processor time. On Windows, it returns the elapsed wall-clock...