@@ -1415,13 +1415,13 @@ def get_filename():
1415
1415
return f ' profile- { time_str} .png '
1416
1416
```
1417
1417
1418
- #### Decorator for timing functions:
1418
+ ### Timing Decorators
1419
+ #### Prints runtime of decorated function:
1419
1420
``` python
1420
1421
from timeit import default_timer
1421
1422
from datetime import timedelta
1422
1423
1423
1424
def stopwatch (func ):
1424
- """ Prints runtime of decorated function."""
1425
1425
def out (* args , ** kwargs ):
1426
1426
start = default_timer()
1427
1427
result = func(* args, ** kwargs)
@@ -1431,13 +1431,12 @@ def stopwatch(func):
1431
1431
return out
1432
1432
```
1433
1433
1434
- #### Decorator for profiling functions :
1434
+ #### Saves run call profile of the decorated function to file :
1435
1435
``` python
1436
1436
from cProfile import Profile
1437
1437
from pstats import Stats
1438
1438
1439
1439
def profiler (func ):
1440
- """ Saves run call profile of the decorated function to file."""
1441
1440
def out (* args , ** kwargs ):
1442
1441
profile = Profile()
1443
1442
result = profile.runcall(func, * args, ** kwargs)
@@ -1451,10 +1450,9 @@ def profiler(func):
1451
1450
return out
1452
1451
```
1453
1452
1454
- #### Decorator for function tracing :
1453
+ #### Prints arguments and output of a decorated function :
1455
1454
``` python
1456
1455
def tracer (func ):
1457
- """ Prints arguments and output of a decorated function."""
1458
1456
def out (* args , ** kwargs ):
1459
1457
result = func(* args, ** kwargs)
1460
1458
arg_list = [repr (x) for x in args]
0 commit comments