Discuss / Python / 交作业

交作业

Topic source

sy107@CHINA

#1 Created at ... [Delete] [Delete and Lock User]
import time

def metric(fn):

    def wrapper(*args, **kw):
        start = time.time()
        fn(*args, **kw)
        end = time.time()
        print('%s executed in %.5f ms' % (fn.__name__, end - start))
        return fn(*args, **kw)
    return wrapper


# 测试
@metricdef fast(x, y):
    time.sleep(0.0012)
    return x + y


@metricdef slow(x, y, z):
    time.sleep(0.1234)
    return x * y * z


f = fast(11, 22)
print('f:',f)
s = slow(11, 22, 33)
print('s:',s)
if f != 33:
    print('测试失败!')
elif s != 7986:
    print('测试失败!')

  • 1

Reply