Home >Backend Development >Python Tutorial >How Can I Measure Function Execution Time in Python?
Measuring Elapsed Time in Python
To gauge the execution time of a function, consider utilizing time.time() to determine the elapsed wall-clock time between two points.
import time start = time.time() print("hello") end = time.time() print(end - start)
This approach yields the execution time in seconds.
Alternately, you may consider employing perf_counter or process_time from Python 3.3 onward, contingent on your specific requirements. Prior to this version, time.clock was recommended for this purpose, though it has since been deprecated in favor of the aforementioned options.
The above is the detailed content of How Can I Measure Function Execution Time in Python?. For more information, please follow other related articles on the PHP Chinese website!