Last active
November 22, 2019 22:30
-
-
Save cclauss/8344302 to your computer and use it in GitHub Desktop.
Useful for measuring elapsed time on computing, i/o, and user tasks.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# an improved version at https://github.com/cclauss/Ten-lines-or-less/blob/master/elapsed_time.py | |
import math, time | |
def elapsedTime(start_time): | |
dt = time.time() - start_time | |
minutes = dt / 60 | |
seconds = dt % 60 | |
centiseconds = math.modf(dt)[0] * 100 | |
return '%02d:%02d.%02d' % (minutes, seconds, centiseconds) | |
#return '{:0>2}:{:0>2}.{:0>2}'.format(minutes, seconds, centiseconds) | |
start_time = time.time() | |
time.sleep(1) | |
print(elapsedTime(start_time)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment