Created
June 2, 2014 21:17
-
-
Save trehn/d27b30ee0e8de0095e1c to your computer and use it in GitHub Desktop.
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
class PrintProfiler(object): | |
""" | |
Will print profiling information. | |
Usage: | |
with PrintProfiler(): | |
[code goes here] | |
""" | |
def __enter__(self): | |
self.pr = cProfile.Profile() | |
self.pr.enable() | |
def __exit__(self, type, value, traceback): | |
self.pr.disable() | |
pstats.Stats(self.pr).sort_stats('cumulative').print_stats() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment