You can make use of the time module in order to measure how much execution time your Python program took.
Let's take a look at an example.
Program:
'''
Program: Find Program Execution Time
in seconds sing Python
Author : Code2care.org
Version : v 1.0
Date : 3 July 2023
'''
import time
program_start_time = time.time()
#Program logic
sum = 0
sum = (333*244*245*134*34523525)/((28323424*23883)*39482983)
program_end_time = time.time()
# Calculate the elapsed time
elapsed_time = program_end_time - program_start_time
# Print the elapsed time
print("Elapsed Time:", elapsed_time, "seconds")
When I do multiple runs, I get different outputs.
Elapsed Time: 0.00014829635620117188 seconds
Elapsed Time: 0.00012087821960449219 seconds
Elapsed Time: 0.00014448165893554688 seconds
Elapsed Time: 0.0001227855682373047 seconds
Elapsed Time: 0.00014138221740722656 seconds
Facing issues? Have Questions? Post them here! I am happy to answer!
More Posts related to Python-Programs,
- Program 5: Find Sum of Two Integer Numbers - 1000+ Python Programs
- 34: Traverse a List in Reverse Order - 1000+ Python Programming
- 22: Send Yahoo! Email using smtplib - SMTP protocol client using Python Program
- 35: Python Program to find the System Hostname
- 27: Measure Elapsed Time for a Python Program Execution
- Program 7: Find Difference of Two Numbers - 1000+ Python Programs
- Program 12: Calculate Area and Circumference of Circle - 1000+ Python Programs
- Program 9: Divide Two Numbers - 1000+ Python Programs
- Program 2: Print your name using print() function - 1000+ Python Programs
- 25: How to rename a file using Python Program
- 17: Find Factorial of a Number - 1000+ Python Programs
- Program 6: Find Sum of Two Floating Numbers - 1000+ Python Programs
- 23: Python Programs to concatenate two Lists
- 36: Python Program Convert Hex String to Integer
- 20 - Python - Print Colors for Text in Terminal - 1000+ Python Programs
- Python Program: Use NumPy to generate a random number between 0 and 1
- 32: Python Program to Find Square Root of a Number
- Program 8: Multiply Two Numbers - 1000+ Python Programs
- Program 11: Calculate Percentage - 1000+ Python Programs
- 18: Get Sub List By Slicing a Python List - 1000+ Python Programs
- 28: Program to Lowercase a String in Python
- Program 1: Print Hello World! - 1000+ Python Programs
- 21: Program to Delete File or Folder in Python
- 29: Program to convert Python dict to dataframe
- 33: Python Program to find the current time in India (IST)
More Posts:
- Add Bookmark macOS Safari - MacOS
- Convert seconds to minutes using JavaScript - JavaScript
- Error : Invalid key hash.The key hash does not match any stored key hashes - Android
- Fix AWS CLI 2 SignatureDoesNotMatch Error - Signature we calculated does not match - AWS
- 17: Find Factorial of a Number - 1000+ Python Programs - Python-Programs
- PHP.ini: How to Remove URL Forward Slash Before Single or Double Quotes - PHP
- Rust: zsh: no such file or directory: ./main - Rust
- Android: Unknown error code during application install : - Android