26 lines
463 B
Python
26 lines
463 B
Python
import time
|
|
from functools import wraps
|
|
|
|
|
|
def cost(func):
|
|
@wraps(func)
|
|
def warpper(*args, **kwargs):
|
|
t1 = time.time()
|
|
res = func(*args, **kwargs)
|
|
t2 = time.time()
|
|
print(func.__name__ + "执行耗时" + str(t2-t1))
|
|
return res
|
|
return warpper
|
|
|
|
@cost
|
|
def test(sleep_time):
|
|
"""
|
|
测试装饰器
|
|
:param sleep_time:
|
|
:return:
|
|
"""
|
|
time.sleep(sleep_time)
|
|
|
|
|
|
print(test.__name__)
|
|
print(test.__doc__) |