fork download
  1. import time, functools
  2. def metric(fn):
  3. @functools.wraps(fn)
  4. def wrapper(*args, **kw):
  5. start = time.time()
  6. result = fn(*args, **kw)
  7. end = time.time()
  8. print('%s executed in %f ms' % (fn.__name__, end - start))
  9. return result
  10. return wrapper
  11.  
  12. # 测试
  13. @metric
  14. def fast(x, y):
  15. time.sleep(0.0012)
  16. return x + y;
  17.  
  18. @metric
  19. def slow(x, y, z):
  20. time.sleep(0.1234)
  21. return x * y * z;
  22.  
  23. f = fast(11, 22)
  24. s = slow(11, 22, 33)
  25. if f != 33:
  26. print('测试失败!')
  27. elif s != 7986:
  28. print('测试失败!')
  29. # your code goes here
  30. # your code goes here
Success #stdin #stdout 0.07s 14120KB
stdin
Standard input is empty
stdout
fast executed in 0.001259 ms
slow executed in 0.123474 ms