Skip to content

Instantly share code, notes, and snippets.

@badbye
Created June 8, 2016 07:21
Show Gist options
  • Save badbye/664c2ecc24cf49ba13526a9c9f4b084b to your computer and use it in GitHub Desktop.
Save badbye/664c2ecc24cf49ba13526a9c9f4b084b to your computer and use it in GitHub Desktop.
python profile decorator
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