Skip to content

Instantly share code, notes, and snippets.

@andrewgodwin
Created August 11, 2015 20:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save andrewgodwin/c38885b580152b255893 to your computer and use it in GitHub Desktop.
Save andrewgodwin/c38885b580152b255893 to your computer and use it in GitHub Desktop.
Handy profiler pattern
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