Sometimes, we want to measure elapsed time in Python.
In this article, we’ll look at how to measure elapsed time in Python.
How to measure elapsed time in Python?
To measure elapsed time in Python, we can use the time
module.
For instance, we write:
import time
start = time.time()
print("hello world")
end = time.time()
print(end - start)
We call time.time
to return the current time as a Unix timestamp and assign the result to start
and end
.
And then we subtract end
from start
to get the elapsed time in seconds.
Conclusion
To measure elapsed time in Python, we can use the time
module.