Created
September 18, 2013 15:19
-
-
Save jakab922/6610735 to your computer and use it in GitHub Desktop.
Measure decorator and context manager, for measuring execution time. For multiple processes, multiple instances are needed.
This file contains hidden or 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
class Measure(object): | |
def __init__(self): | |
self.__elapsed = None | |
def __enter__(self): | |
self.__start = time() | |
def __exit__(self, *args): | |
self.__elapsed = time() - self.__start | |
@property | |
def elapsed(self): | |
return self.__elapsed | |
def __call__(self, fn): | |
@wraps(fn) | |
def measured(*args, **kwargs): | |
start = time() | |
ret = fn(*args, **kwargs) | |
return time() - start, ret | |
return measured | |
measure = Measure() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment