Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@trehn
Created June 2, 2014 21:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trehn/d27b30ee0e8de0095e1c to your computer and use it in GitHub Desktop.
Save trehn/d27b30ee0e8de0095e1c to your computer and use it in GitHub Desktop.
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