Measuring execution time
In order to measure how fast a piece of code is executed, we need to measure its execution time. The time measured is relative and varies, depending on a number of factors: the operating system, whether there are other programs running, the hardware, and so on.
For our efficiency tests, we will measure the execution time, make changes in the code, and measure it again. In this way, we will see if the changes improve the code efficiency or not.
Let's start with a simple example and measure how long it takes to run.
As before, make a copy of the previous chapter folder in your
geopy
project and rename it asChapter8
. Your project structure should look like this:├───Chapter1 ├───Chapter2 ├───Chapter3 ├───Chapter4 ├───Chapter5 ├───Chapter6 ├───Chapter7 ├───Chapter8 │ ├───experiments │ ├───map_maker │ ├───output │ └───utils └───data
Click on your
experiments
folder and create a new Python file inside it. Name that filetiming.py
.Now add the following code to that...