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
Recommended:-Python Random Number Generator Code
Recommended:-Python program for Zip, Zap and Zoom game
Recommended:-Python Program to Swap Two Numbers
Recommended:-Python Program to Find n-th term of Fibonacci Series
Recommended:-Python Program For Calculator
Recommended:-Python Program to Find Strong Number
Recommended:-Python Program to Convert cm to Feet and Inches
Recommended:-How to Reverse a List in Python
Recommended:-Python Program to Convert Celsius to Fahrenheit
Recommended:-Python Program to Find Standard Deviation
Recommended:-Python Program to Check Perfect Number
Recommended:-Python Program to Display Calendar
Recommended:-Python Program to Print Alphabets from A to Z
Recommended:-Python Program to Find Roots of Quadratic Equation
Recommended:-Python Program to Find the Variance