From f646d1922b6d019f3cb0a1ef65e2a95c8d75d291 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Sat, 29 Dec 2018 17:28:25 +0100 Subject: [PATCH] Profile --- README.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index c61bc3c..8cb81d3 100644 --- a/README.md +++ b/README.md @@ -1415,13 +1415,13 @@ def get_filename(): return f'profile-{time_str}.png' ``` -#### Decorator for timing functions: +### Timing Decorators +#### Prints runtime of decorated function: ```python from timeit import default_timer from datetime import timedelta def stopwatch(func): - """Prints runtime of decorated function.""" def out(*args, **kwargs): start = default_timer() result = func(*args, **kwargs) @@ -1431,13 +1431,12 @@ def stopwatch(func): return out ``` -#### Decorator for profiling functions: +#### Saves run call profile of the decorated function to file: ```python from cProfile import Profile from pstats import Stats def profiler(func): - """Saves run call profile of the decorated function to file.""" def out(*args, **kwargs): profile = Profile() result = profile.runcall(func, *args, **kwargs) @@ -1451,10 +1450,9 @@ def profiler(func): return out ``` -#### Decorator for function tracing: +#### Prints arguments and output of a decorated function: ```python def tracer(func): - """Prints arguments and output of a decorated function.""" def out(*args, **kwargs): result = func(*args, **kwargs) arg_list = [repr(x) for x in args]