Guest User

Untitled

a guest
Nov 20th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. """Often it is useful to time a segment of code with a semantically relevant description instead of
  2. relying on piecing together profiling information. This is especially useful for code segments that
  3. only run once or a few times (e.g., step by step hadoop workflows with several jobs)."""
  4.  
  5. import contextlib
  6. import time
  7. @contextlib.contextmanager
  8. def timer(name):
  9. st = time.time()
  10. yield
  11. print('[%s]: %s' % (name, time.time() - st))
  12.  
  13. # Example of usage
  14. with timer('CPU Bound Loop'):
  15. [x ** x for x in range(1000)]
Add Comment
Please, Sign In to add comment