How to Check Python Program Execution Time

How to check Python program execution time; Through this tutorial, i am going to show you how to check Python program execution.

Calculate Time taken by a Program to Execute in Python

  • Algorithm to find the execution time of a Sample Python Program/Script
  • How to Check Python Program Execution

Algorithm to find the execution time of a Sample Python Program/Script

  • First of all, import the datetime module in your python script/program.
  • Take values from the user.
  • Find the initial time by using now() function and then assign it to a variable which is time_start.
  • Complete the task in the program.
  • Here, we will also find the current time and assign it to a variable which is time_end.
  • To know the execution time simply find the difference between the time_end and time_start i.e time_end – time_start.

How to Check Python Program Execution

#Python Program to find the execution time of python script
# importing the modules
from datetime import datetime
A=int(input("Enter the A value: "))
B=int(input("Enter the B value: "))
time_start=datetime.now()
C = A + B
print("A + B = :",C)
time_end=datetime.now()
e= time_end - time_start
print("The execution time of python program is : ",e)

Output

Enter the A value:  8
Enter the B value:  5
A + B = : 13
The execution time of python program is :  0:00:00.000054

Recommended Python Tutorials

Leave a Comment