Skip to content

Instantly share code, notes, and snippets.

@js51
Created June 1, 2024 02:56
Show Gist options
  • Select an option

  • Save js51/408bfaf53c3db877ebca182a78f90557 to your computer and use it in GitHub Desktop.

Select an option

Save js51/408bfaf53c3db877ebca182a78f90557 to your computer and use it in GitHub Desktop.
Code for profiling functions in python
from cProfile import Profile
from pstats import SortKey, Stats
with Profile() as profile:
# Code goes here
my_function()
# # #
print(
Stats(profile)
.strip_dirs()
.sort_stats('cumtime')
.print_stats()
.print_callees()
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment