Python___语法糖
import time
def timer(func):
def deco():
start_time=time.time()
func()
stop_time=time.time()
print("the func run time is %s" %(stop_time-start_time))
return deco
def test1():
time.sleep(3)
print('in the test1 !!!!!')
print(timer(test1))
test1=timer(test1)
test1()
执行结果:
.deco at 0x005F5270>
in the test1 !!!!!
the func run time is 3.0
............................................................................
print(timer(test1))
的执行结果为:
.deco at 0x005F5270>
test1=timer(test1)
test1()
的执行结果为:
in the test1 !!!!!
the func run time is 3.0