Last active
July 20, 2018 22:54
-
-
Save mattiaslundberg/3ab3fe686ba7f3d2cd13 to your computer and use it in GitHub Desktop.
Inline profiling in Python (2.7)
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
# https://docs.python.org/2/library/profile.html | |
import cProfile | |
pr = cProfile.Profile() | |
pr.enable() | |
try: | |
pass # Code to profile | |
finally: | |
pr.disable() | |
pr.dump_stats('filename') |
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 pstats | |
s = pstats.Stats('filename') | |
# print calls taking most time | |
s.sort_stats('tottime').print_stats('appname', .05) | |
# print most called calls | |
s.sort_stats('ncalls').print_stats('appname', .05) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment