Skip to content

Instantly share code, notes, and snippets.

@zenweasel
Created October 5, 2015 20:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zenweasel/c16a09b0bf5a158b5e3b to your computer and use it in GitHub Desktop.
Save zenweasel/c16a09b0bf5a158b5e3b to your computer and use it in GitHub Desktop.
Used for timing module execution time. Put in in the site_packages directory and import it at the top of the module
import atexit
from time import clock
def seconds_to_str(t):
return "%d:%02d:%02d.%03d" % \
reduce(lambda ll, b: divmod(ll[0], b) + ll[1:],
[(t * 1000,), 1000, 60, 60])
line = "=" * 40
def log(s, elapsed=None):
print line
print seconds_to_str(clock()), '-', s
if elapsed:
print "Elapsed time:", elapsed
print line
print
def endlog():
end = clock()
elapsed = end - start
log("End Program", seconds_to_str(elapsed))
def now():
return seconds_to_str(clock())
start = clock()
atexit.register(endlog)
log('Start Program')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment