Created
February 12, 2020 16:19
-
-
Save tldrafael/6ea5d41d6f919c69f7ff6da534906f84 to your computer and use it in GitHub Desktop.
Decorator to profile python functions
This file contains hidden or 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
from line_profiler import LineProfiler | |
def do_profile(follow=[]): | |
def inner(func): | |
def profiled_func(*args, **kwargs): | |
try: | |
profiler = LineProfiler() | |
profiler.add_function(func) | |
for f in follow: | |
profiler.add_function(f) | |
profiler.enable_by_count() | |
return func(*args, **kwargs) | |
finally: | |
profiler.print_stats() | |
return profiled_func | |
return inner |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment