def timefunc(func):
"""Decorator to calc function's time cost."""
import time
def wrapper(*args, **kw):
st = time.perf_counter()
res = func(*args, **kw)
et = time.perf_counter()
print(f'\n{func.__module__}.{func.__name__} cost {et - st}s')
return res
return wrapper
import time
def func1():
time.sleep(2)
timefunc(func1)()