import time
def timer(func):
def gf():
start_time = time.time()
func()
end_time = time.time()
print('func运行的时间为:', end_time - start_time)
return gf
def foo():
time.sleep(3)
print('in foo')
foo = timer(foo)
foo()
以上等价于
import time
def timer(func):
def gf():
start_time = time.time()
func()
end_time = time.time()
print('func运行的时间为:', end_time - start_time)
return gf
@timer
def foo():
time.sleep(3)
print('in foo')
foo()
标签:end,start,Python,--,func,time,foo,高阶,def From: https://www.cnblogs.com/jackchen28/p/18163782