Skip to content

Instantly share code, notes, and snippets.

@cclauss
Last active November 22, 2019 22:30
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cclauss/8344302 to your computer and use it in GitHub Desktop.
Save cclauss/8344302 to your computer and use it in GitHub Desktop.
Useful for measuring elapsed time on computing, i/o, and user tasks.
# 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