Python-How to measure time elapsed?
How python measure time elapsed by using the timeit module if I want to start counting time somewhere in my code and then get the passed time? I think I am using the module wrong.
import timeit
start = timeit.timeit()
print "hello"
end = timeit.timeit()
print end - startÂ
To measure the elapsed wall-clock time between 2 points, you may use time.time():
The following code gives the execution time in seconds:
import time
start = time.time()
print("hello")
end = time.time()
print(end - start)
Note:
To measure time elapsed during program's execution, either use time. clock() or time. time() functions. The python docs state that this function should be used for benchmarking purposes.