23 lines
496 B
Python
23 lines
496 B
Python
# decorators/time.measure.deco2.py
|
|
from time import sleep, time
|
|
from functools import wraps
|
|
|
|
|
|
def measure(func):
|
|
@wraps(func)
|
|
def wrapper(*args, **kwargs):
|
|
t = time()
|
|
func(*args, **kwargs)
|
|
print(func.__name__, 'took:', time() - t)
|
|
return wrapper
|
|
|
|
|
|
@measure
|
|
def f(sleep_time=0.1):
|
|
"""I'm a cat. I love to sleep! """
|
|
sleep(sleep_time)
|
|
|
|
|
|
f(sleep_time=0.3) # f took: 0.3010902404785156
|
|
print(f.__name__, ':', f.__doc__) # f : I'm a cat. I love to sleep!
|