Created
April 3, 2018 19:29
-
-
Save sean-adler/6f493b6741cc792c1cbe24c896c54344 to your computer and use it in GitHub Desktop.
Write cProfile stats to human-readable text file
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 | |
import pstats | |
prof = cProfile.Profile() | |
prof.run('<YOUR CODE>') | |
prof.sort_stats('cumtime') | |
prof.dump_stats('output.prof') | |
stream = open('output.txt', 'w') | |
stats = pstats.Stats('output.prof', stream=stream) | |
stats.sort_stats('cumtime') | |
stats.print_stats() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I had to leave out line 6 for my code to work.