import time def timer(func):#timer(test1) func=test1 def deco(): start_time=time.time() func()#run test1 stop_time=time.time() print('the func time is %s'%(stop_time-start_time)) return deco @timer#@timmer与test1=timer(test1)等价 #原代码 def test1(): time.sleep(1) print('in the test1') @timer#@timmer与test2=timer(test2)等价 # 原代码 def test2(): time.sleep(2) print('in the test2') print(timer(test1))#打印的是timer(test1)的返回值 ''' test1=timer(test1)#timer(test1())是错误的,加括号将test1的返回值传递给timer,应该将test1的内存地址传递给timer ''' test1() ''' test2=timer(test2) ''' test2()