Created
January 8, 2013 21:40
-
-
Save charlee/4488238 to your computer and use it in GitHub Desktop.
generic decorator with functools.wraps
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
import functools | |
def timethis(func): | |
"""A profiling function used to record the time consumed on a function call.""" | |
@functools.wraps(func) | |
def _(self, *a, **kw): | |
start = time() | |
ret = func(self, *a, **kw) | |
end = time() | |
total_time = end - start | |
self.queries.append({ | |
'func': func.__name__, | |
'start': start, | |
'end': end, | |
'total': total_time, | |
}) | |
return ret | |
return _ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment