Created
April 13, 2016 09:29
-
-
Save TheML9I/2a5fe8f9462edf57fb4402c4cbfab9fb to your computer and use it in GitHub Desktop.
Just a cProfile decorator to profile methods or funtions
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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.