fork download
  1. import functools,time
  2. def metric(fn):
  3. @functools.wraps(fn)
  4. def wrapper(*args, **kwargs):
  5. print(f"begin call {fn.__name__}()")
  6. result = fn(*args, **kwargs) # 调用原函数
  7. print(f"end call {fn.__name__}()")
  8. return result
  9. return wrapper
  10.  
  11. # 测试
  12. @metric
  13. def fast(x, y):
  14. time.sleep(0.0012)
  15. return x + y;
  16.  
  17. @metric
  18. def slow(x, y, z):
  19. time.sleep(0.1234)
  20. return x * y * z;
  21.  
  22. f = fast(11, 22)
  23. s = slow(11, 22, 33)
  24. if f != 33:
  25. print('测试失败!')
  26. elif s != 7986:
  27. print('测试失败!')
  28. # your code goes here
  29. # your code goes here
Success #stdin #stdout 0.09s 14160KB
stdin
Standard input is empty
stdout
begin call fast()
end call fast()
begin call slow()
end call slow()