Skip to content

Instantly share code, notes, and snippets.

@w0w
Created January 6, 2015 10:29
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 w0w/e2879656bd4f1f67a0ce to your computer and use it in GitHub Desktop.
Save w0w/e2879656bd4f1f67a0ce to your computer and use it in GitHub Desktop.
'''Handy Class for time monitoring'''
from __future__ import print_function
import time
class timer(object):
def __init__(self, func=print):
self.func = func
def __enter__(self):
self.time = time.time()
def __exit__(self, type, value, traceback):
total_time = time.time() - self.time
self.func(total_time)
'''To know how long a code takes to run'''
with timer():
# do something
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment