Skip to content

Instantly share code, notes, and snippets.

@durden
Created March 20, 2013 19:17
Show Gist options
  • Save durden/5207587 to your computer and use it in GitHub Desktop.
Save durden/5207587 to your computer and use it in GitHub Desktop.
Profile decorator take from rwarren talk, 'A brief intro to profiling in Python'
def profile_this(fn):
def profiled_fn(*args, **kwargs):
fpath = fn.__name__ + '.profile'
prof = cProfile.Profile()
ret = prof.runcall(fn, *args, **kwargs)
prof.dump_stats(fpath)
return ret
return profiled_fn
@profile_this
def silly_delay():
[f() for f in (delay1, delay2, delay3)]
Taken from: [https://speakerdeck.com/rwarren/a-brief-intro-to-profiling-in-python](https://speakerdeck.com/rwarren/a-brief-intro-to-profiling-in-python)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment