Skip to content

Instantly share code, notes, and snippets.

@cshoe
Last active January 8, 2016 18:54
Show Gist options
  • Save cshoe/ad82337f2d1d09d49b1a to your computer and use it in GitHub Desktop.
Save cshoe/ad82337f2d1d09d49b1a to your computer and use it in GitHub Desktop.
import time
from contextlib import contextmanager
@contextmanager
def timed(metric, tags=None):
start = time.time()
try:
yield tags
finally:
print tags
dt = (time.time() - start) * 1000.0
print dt
def main():
with timed('asdf', tags={'asdf': 'qwer'}) as yolo:
yolo['qqq'] = 'aaa'
time.sleep(1)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment