Skip to content

Instantly share code, notes, and snippets.

@w0w
Created January 6, 2015 10:29
Embed
What would you like to do?
'''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