def metric(func):
'''计算函数运行时间函数'''
@functools.wraps(func)
def inner(*args,**kwargs):
f1=time.time()
res=func(*args,**kwargs)
f2=time.time()
print(f2-f1)
return res
return inner
@metric
def fast(x, y):
time.sleep(0.0012)
return x + y;
def slow(x, y, z):
time.sleep(0.1234)
return x * y * z;
f = fast(11, 22)
s = slow(11, 22, 33)
if f != 33:
print('测试失败!')
elif s != 7986:
Sign in to make a reply
阿财
def metric(func):
'''计算函数运行时间函数'''
@functools.wraps(func)
def inner(*args,**kwargs):
f1=time.time()
res=func(*args,**kwargs)
f2=time.time()
print(f2-f1)
return res
return inner
@metric
def fast(x, y):
time.sleep(0.0012)
return x + y;
@metric
def slow(x, y, z):
time.sleep(0.1234)
return x * y * z;
f = fast(11, 22)
s = slow(11, 22, 33)
if f != 33:
print('测试失败!')
elif s != 7986:
print('测试失败!')