装饰器

#Author:Kevin_hou

import  time
def timer(func):    #timer(test1)   func= test1
    def deco(*args, **kwargs):
        start_time= time.time()
        func(*args, **kwargs)
        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 test')

@timer
def test2():
    time.sleep(3)
    print('in the test2')
test1()
test2()

  

posted @ 2020-08-11 18:50  JRS077  阅读(62)  评论(0编辑  收藏  举报