You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
463B

  1. import time
  2. from functools import wraps
  3. def cost(func):
  4. @wraps(func)
  5. def warpper(*args, **kwargs):
  6. t1 = time.time()
  7. res = func(*args, **kwargs)
  8. t2 = time.time()
  9. print(func.__name__ + "执行耗时" + str(t2-t1))
  10. return res
  11. return warpper
  12. @cost
  13. def test(sleep_time):
  14. """
  15. 测试装饰器
  16. :param sleep_time:
  17. :return:
  18. """
  19. time.sleep(sleep_time)
  20. print(test.__name__)
  21. print(test.__doc__)