Created
December 30, 2018 14:18
-
-
Save amb/ec371804f6c22c658565d1fc45f2b51b to your computer and use it in GitHub Desktop.
Simple profiling
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, io | |
def profiling_start(): | |
# profiling | |
pr = cProfile.Profile() | |
pr.enable() | |
return pr | |
def profiling_end(pr): | |
# end profile, print results | |
pr.disable() | |
s = io.StringIO() | |
sortby = 'cumulative' | |
ps = pstats.Stats(pr, stream=s) | |
ps.strip_dirs().sort_stats(sortby).print_stats(20) | |
print(s.getvalue()) | |
pr = profiling_start() | |
do_a_thing() | |
profiling_end(pr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment