Created
January 6, 2015 10:29
-
-
Save w0w/e2879656bd4f1f67a0ce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'''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