python 时间戳装饰器
作者:互联网
点击查看代码
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)
标签:return,python,counter,时间,func,time,print,装饰,def 来源: https://www.cnblogs.com/seven-lv/p/16609785.html