Skip to content

Instantly share code, notes, and snippets.

@ThatDevopsGuy
Created February 21, 2013 17:31
Show Gist options
  • Save ThatDevopsGuy/5006525 to your computer and use it in GitHub Desktop.
Save ThatDevopsGuy/5006525 to your computer and use it in GitHub Desktop.
EmbeddedTimer is a fun timer!
class EmbeddedTimer():
def __init__(self):
self.start = time()
def stop(self):
end = time()
diff = end - self.start
if 1 < diff:
# Get the remainder:
r = round(diff % 1, 2)
diff = int(diff)
if 0.7 <= r:
return 'took a little under ' + str(diff + 1) + ' seconds'
elif 0.4 <= r < 0.7:
return 'took just about ' + str(diff) + '-and-a-half seconds'
elif 0.1 <= r < 0.4:
if diff == 1:
return 'took a little over ' + str(diff) + ' second'
else:
return 'took a little over ' + str(diff) + ' seconds'
else:
if diff == 1:
return 'took (near as makes no difference) ' + str(diff) + ' second'
else:
return 'took (near as makes no difference) ' + str(diff) + ' seconds'
elif 0.86 < diff <= 1:
return 'took less than a second'
elif 0.4 < diff <= 0.86:
return 'was faster than a heartbeat'
elif 0.2 < diff <= 0.4:
return 'was faster than the blink of an eye'
elif 0.134 < diff <= 0.2:
return 'was faster than it takes the brain to recognize emotion'
elif 0.125 < diff <= 0.134:
return 'was faster than light traveling around the Earth\'s equator.'
elif 0.0625 < diff <= 0.125:
return 'was faster than a 32nd note'
elif 0.05 < diff <= 0.0625:
return 'was faster than a 64th note'
elif 0.033 < diff <= 0.05:
return 'was faster than the gearchange of a Lamborghini® Aventador®'
elif 0.0167 < diff <= 0.033:
return 'was faster than a frame of a movie'
elif 0.008 < diff <= 0.0167:
return 'was faster than a Jiffy'
elif 0.005 < diff <= 0.008:
return 'was faster than a camera shutter'
elif 0.0033 < diff <= 0.005:
return 'was faster than a honeybee\'s wing flap'
elif 0.001 < diff <= 0.0033:
return 'was faster than the detonation of C4'
elif diff <= 0.001:
return 'was faster than a camera flash'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment