This article aims to show how to measure the time taken by the program to execute. Calculating time helps to optimize your Python script to perform better.
Approach #1 :
A simple solution to it is to use time module to get the current time. The following steps calculate the running time of a program or section of a program.
- Store the starting time before the first line of the program executes.
- Store the ending time after the last line of the program executes.
- Print the difference between start time and end time.
Code #1 :
GeeksForGeeks GeeksForGeeks GeeksForGeeks GeeksForGeeks GeeksForGeeks Total runtime of the program is 1.0010437965393066
Approach #2 : Using
Note: Output may vary depending on the system or server load.
To read more about Timeit modulule, refer – Timeit in Python with Examples
- Python program to find difference between current time and given time
- Execute a String of Code in Python
- Python | How to time the program
- Python | Execute and parse Linux commands
- Python program to get Current Time
- Statistical Functions in Python | Set 2 ( Measure of Spread)
- Measure similarity between images using Python-OpenCV
- Python | Program to generate one-time password (OTP)
- Python subprocess module to execute programs written in different languages
- Statistical Functions in Python | Set 1 (Averages and Measure of Central Location)
- Python program to convert time from 12 hour to 24 hour format
- Python | Measure similarity between two sentences using cosine similarity
- Time Functions in Python | Set 1 (time(), ctime(), sleep()...)
- Python | time.time() method
- PyQt5 QColorDialog - How to execute it ?
- ML | V-Measure for Evaluating Clustering Performance
- Program to calculate the Round Trip Time (RTT)
- time.sleep() in Python
- Time tuple in Python
- Python Program for Efficient program to print all prime factors of a given number