Skip to content

Instantly share code, notes, and snippets.

@mvmocanu
Last active December 14, 2015 20:08
Show Gist options
  • Save mvmocanu/5141177 to your computer and use it in GitHub Desktop.
Save mvmocanu/5141177 to your computer and use it in GitHub Desktop.
Profile decorator Used for profiling a function. The generated profile can be viewed with: http://www.vrplumber.com/programming/runsnakerun/
import cProfile
import time
def profile_this(fn):
def profiled_fn(*args, **kwargs):
fpath = "%s-%s.profile" % (fn.__name__, round(time.time()))
prof = cProfile.Profile()
ret = prof.runcall(fn, *args, **kwargs)
prof.dump_stats(fpath)
return ret
return profiled_fn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment