算出函数运行时间
# coding:utf-8
import time
def timer(func):
def wrapper(*args, **kwargs):
t0 = time.perf_counter()
func(*args, **kwargs)
t1 = time.perf_counter()
print('耗时:{0}s'.format(t1 - t0))
return wrapper()
@timer
def test():
print('运行test函数')
>>>运行test函数
>>>耗时:1.23554356e-06s