With the Time module in python is it possible to measure elapsed time? If so, how do I do that?
I need to do this so that if the cursor has been in a widget for a c
For users that want better formatting,
import time
start_time = time.time()
# your script
elapsed_time = time.time() - start_time
time.strftime("%H:%M:%S", time.gmtime(elapsed_time))
will print out, for 2 seconds:
'00:00:02'
and for 7 minutes one second:
'00:07:01'
note that the minimum time unit with gmtime is seconds. If you need microseconds consider the following:
import datetime
start = datetime.datetime.now()
# some code
end = datetime.datetime.now()
elapsed = end - start
print(elapsed)
# or
print(elapsed.seconds,":",elapsed.microseconds)
strftime documentation