# 装饰器使用小高潮 import time def timr(func): # timr(func)=timr(test1) func=test1 def deco(*args): start_time = time.time() func(*args) # run test1() stop_time = time.time() print("the func run time is {}".format(stop_time - start_time)) return deco @timr # test1 = timr(test1) def test1(): time.sleep(2) print("in the test1") @timr def test2(name,age): time.sleep(3) print("test2 name is {},age is {}".format(name,age)) test1() test2("hujinali", 21)