Created
May 15, 2022 07:56
-
-
Save matanper/e2802864fe408e634ae02971028b458b to your computer and use it in GitHub Desktop.
Python code snippet to run run-time profiling for python code
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 io | |
import pstats | |
pr = cProfile.Profile() | |
pr.enable() | |
### Code to profile here | |
pr.disable() | |
s = io.StringIO() | |
ps = pstats.Stats(pr, stream=s).sort_stats('time') | |
ps.print_stats() | |
print(s.getvalue()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment