Skip to content

Instantly share code, notes, and snippets.

@matanper
Created May 15, 2022 07:56
Show Gist options
  • Save matanper/e2802864fe408e634ae02971028b458b to your computer and use it in GitHub Desktop.
Save matanper/e2802864fe408e634ae02971028b458b to your computer and use it in GitHub Desktop.
Python code snippet to run run-time profiling for python code
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