点击查看代码
import time
from functools import wraps
def timer(func):
@wraps(func)
def inner(*args, **kwargs):
start = time.time()
res = func(*args, **kwargs)
end = time.time()
print("{0}运行耗时: {1:.2f}".format(func.__name__, end - start))
return res
return inner
@timer
def counter(x):
print("counter running!!!")
time.sleep(3)
return x
x = counter(100)
print(counter.__name__)
print(x)
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/281397.html