Created
March 13, 2013 15:05
-
-
Save stengaard/5152995 to your computer and use it in GitHub Desktop.
Handy decorator for profiling. Stolen from https://speakerdeck.com/rwarren/a-brief-intro-to-profiling-in-python
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
def profile_this(fn): | |
import cProfile | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment