Created
June 8, 2016 07:21
-
-
Save badbye/664c2ecc24cf49ba13526a9c9f4b084b to your computer and use it in GitHub Desktop.
python profile decorator
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 | |
def profileit(name): | |
def inner(func): | |
def wrapper(*args, **kwargs): | |
prof = cProfile.Profile() | |
retval = prof.runcall(func, *args, **kwargs) | |
# Note use of name from outer scope | |
prof.dump_stats(name) | |
return retval | |
return wrapper | |
return inner | |
@profileit("profile_for_func1_001") | |
def func1(...) | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment