Skip to content

Instantly share code, notes, and snippets.

@user454322
Created December 1, 2022 02:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save user454322/911e0a8eb34cd3fd2bf34551e3ce7035 to your computer and use it in GitHub Desktop.
Save user454322/911e0a8eb34cd3fd2bf34551e3ce7035 to your computer and use it in GitHub Desktop.
Python profiling
import cProfile
import time
#...
def set_up(self):
#...
self.pr = cProfile.Profile()
self.pr.enable()
def tear_down(self):
#...
self.pr.disable()
#self.pr.print_stats(sort="tottime")
self.pr.dump_stats('/tmp/example.prof')
`snakeviz /tmp/example.prof`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment