-
-
Save simonw/51582e2e8a7c421737a2 to your computer and use it in GitHub Desktop.
Handy profiler pattern
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, pstats, StringIO | |
pr = cProfile.Profile() | |
pr.enable() | |
# ... do something ... | |
pr.disable() | |
s = StringIO.StringIO() | |
sortby = 'cumulative' | |
ps = pstats.Stats(pr, stream=s).sort_stats(sortby) | |
ps.print_stats() | |
print s.getvalue() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment