Advertisement
Guest User

Untitled

a guest
Mar 8th, 2017
5,906
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # source: http://stackoverflow.com/a/1557906/6009280
  2.  
  3. import atexit
  4. from time import clock
  5. from functools import reduce
  6.  
  7.  
  8. def seconds_to_str(t):
  9. return "%d:%02d:%02d.%03d" % \
  10. reduce(lambda ll, b: divmod(ll[0], b) + ll[1:],
  11. [(t * 1000,), 1000, 60, 60])
  12.  
  13.  
  14. line = "=" * 40
  15.  
  16.  
  17. def log(s, elapsed=None):
  18. print(line)
  19. print(seconds_to_str(clock()), '-', s)
  20. if elapsed:
  21. print("Elapsed time:", elapsed)
  22. print(line)
  23. print()
  24.  
  25.  
  26. def endlog():
  27. end = clock()
  28. elapsed = end - start
  29. log("End Program", seconds_to_str(elapsed))
  30.  
  31.  
  32. def now():
  33. return seconds_to_str(clock())
  34.  
  35.  
  36. start = clock()
  37. atexit.register(endlog)
  38. log("Start Program")
Advertisement
RAW Paste Data Copied
Advertisement