- # _*_coding:utf-8_*_
- # Author:len liu
- import time
- def bar():
- # start_time=time.time()
- time.sleep(1)
- print('in the bar')
- # stop_time=time.time()
- # print('use time %s' %use_time) #bar() -------------->
- #in the bar
- #use time 1.000830888748169
- def timer(fun):
- def add_use_time():
- start_time=time.time()
- fun()
- stop_time=time.time()
- print('use time %s' %(stop_time - start_time))
- return add_use_time
- bar=timer(bar)
- bar()
- #--------------> #in the bar
- #use time 1.000830888748169
装饰器
来源: http://www.bubuko.com/infodetail-2688070.html