Measure script execution time#

There are several options for estimating execution time of the script. The simplest options are:

  • Linux time utility

  • and Python datetime module

When measuring the execution time of script in this case, high accuracy is not important. The main thing is to compare the execution time of script in different variants.


Linux time utility allows you to measure the execution time of a script. To use time utility it is enough to write time before starting the script:

$ time python
real    0m4.712s
user    0m0.336s
sys     0m0.064s

We are interested in real time. In this case, it’s 4.7 seconds.


The second option is a datetime module. This module allows working with time and dates in Python.


from datetime import datetime
import time

start_time =

#Code is running here

print( - start_time)


$ python