Skip to content

Instantly share code, notes, and snippets.

@TheML9I
Created April 13, 2016 09:29
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 TheML9I/2a5fe8f9462edf57fb4402c4cbfab9fb to your computer and use it in GitHub Desktop.
Save TheML9I/2a5fe8f9462edf57fb4402c4cbfab9fb to your computer and use it in GitHub Desktop.
Just a cProfile decorator to profile methods or funtions
def do_cprofile(func):
import cProfile
def profiled_func(*args, **kwargs):
profile = cProfile.Profile()
try:
profile.enable()
result = func(*args, **kwargs)
profile.disable()
return result
finally:
profile.print_stats()
return profiled_func
@TheML9I
Copy link
Author

TheML9I commented Apr 13, 2016

To use it just do:

@do_cprofile
def your_func():
....

In the end of processing you will get good report. Give additional parameters to customize report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment