Python Program to Measure the Elapsed Time in Python – 2024

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

Table of Contents

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

Leave a Reply

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