Last active
December 14, 2015 20:08
-
-
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/
This file contains 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 | |
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