Skip to content

Instantly share code, notes, and snippets.

@charlee
Created January 8, 2013 21:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save charlee/4488238 to your computer and use it in GitHub Desktop.
Save charlee/4488238 to your computer and use it in GitHub Desktop.
generic decorator with functools.wraps
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