Join our newsletter for the latest updates.

Python Program to Measure the Elapsed Time in Python

In this example, you will learn to measure the elapsed time.

To understand this example, you should have the knowledge of the following Python programming topics:

Example 1: Using time module

import time

start = time.time()


end = time.time()
print(end - start)



In order to calculate the time elapsed in executing a code, the time module can be used.

  • Save the timestamp at the beginning of the code start using time().
  • Save the timestamp at the end of the code end.
  • Find the difference between the end and start, which gives the execution time.

The execution time depends on the system.

Example 2: Using timeit module

from timeit import default_timer as timer

start = timer()


end = timer()
print(end - start)



Similar to Example 1, we use timer() method from timeit module.

timeit provides the most accurate results.

Did you find this article helpful?