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