Python Program to Measure the Elapsed Time in Python – 2023

Hey guys, in this blog we will see a Python Program to Measure the Elapsed Time in Python.

Example 1: Using the time module

import time

start = time.time()
print(113*14.24)
end = time.time()

print(end - start)

Output

1609.1200000000001
0.0
  • In this example, we will use the time module to measure elapsed time for an operation.
  • Before the operation, we will define a start time object using time.time().
  • Similarly, when the operation is done, we will define an end time object using time.time().

Example 2: Using the timeit module

from timeit import default_timer as timer

start = timer()
print(113*14.24)
end = timer()

print(end - start)

Output

1609.1200000000001
0.00025229999999965
  • Here also we are doing something similar but using a different python module.
  • Here we have used timeit.default_timer module to measure start and end time.
  • Finally calculating the time elapsed by subtracting the start time from the end time.

Check out our other python programming examples

Abhishek Sharma
Abhishek Sharma

Started my Data Science journey in my 2nd year of college and since then continuously into it because of the magical powers of ML and continuously doing projects in almost every domain of AI like ML, DL, CV, NLP.

Articles: 521

Leave a Reply

Your email address will not be published. Required fields are marked *