Created
February 28, 2013 13:40
-
-
Save dnouri/5056788 to your computer and use it in GitHub Desktop.
A profile function decorator. Writes profile to <functionname>.profile. Inspect the profile with runsnakerun or the like.
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
import cProfile | |
from functools import wraps | |
def profile(func): | |
@wraps(func) | |
def wrapper(*args, **kwargs): | |
cProfile.runctx( | |
'result = func(*args, **kwargs)', | |
globals(), | |
locals(), | |
filename='%s.profile' % func.__name__, | |
) | |
return locals()['result'] | |
return wrapper |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment