This article is a main learning note for python beginners. Describes how to measure the time taken for processing with python.
speed.py
# coding utf-8
import time
#Start measurement
start = time.time()
#Write the process here(Measure the time taken for this process(Stop here for 2 seconds))
time.sleep(2)
#End of measurement
end = time.time()
#Output measurement results
print(str(end-start) + ' seconds')
The processing speed can be calculated by [time when processing was completed-time when processing was started]
.
It is more accurate to use time.perf_counter than time.time.
speed.py
# coding utf-8
import time
start = time.perf_counter()
time.sleep(2)
end = time.perf_counter()
print(str(end-start) + ' seconds')
To be honest, I think you can use either one.
Recommended Posts