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
@timer
def test1():
time.sleep(3)
print("in the test1")
@timer
def test2():
time.sleep(3)
print("in the test2")
#test1=timer(test1)#运行装饰器
test1()
test2()
in the test1
the func run time is 3.0100934505462646
in the test2
the func run time is 3.0110301971435547