Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """Often it is useful to time a segment of code with a semantically relevant description instead of
- relying on piecing together profiling information. This is especially useful for code segments that
- only run once or a few times (e.g., step by step hadoop workflows with several jobs)."""
- import contextlib
- import time
- @contextlib.contextmanager
- def timer(name):
- st = time.time()
- yield
- print('[%s]: %s' % (name, time.time() - st))
- # Example of usage
- with timer('CPU Bound Loop'):
- [x ** x for x in range(1000)]
Add Comment
Please, Sign In to add comment