码迷,mamicode.com
首页 > 其他好文 > 详细

装饰器

时间:2018-11-06 00:53:10      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:span   code   color   test   fun   int   app   time()   装饰器   

import time
def timmer(func):
    def wrapper():
        start_time = time.time()
        func()
        stop_time=time.time()
        print(test函数运行时间为%s%(stop_time-start_time))
    return wrapper

@timmer
def test():
    time.sleep(1)
    print(test函数运行完毕)

test()

----运行结果
test函数运行完毕
test函数运行时间为1.0002305507659912

 

装饰器

标签:span   code   color   test   fun   int   app   time()   装饰器   

原文地址:https://www.cnblogs.com/Forever77/p/9912270.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!