By the test function to add a decorator!

import time
def timer(func):
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 #test1=time(test1)
def test1():
time.sleep(3)
print('in the test1')

@timer
def test2(name,age):
time.sleep(3)
print (name,age)

test1()
test2('Sins Ze',47)

Guess you like

Origin www.cnblogs.com/lyzfp/p/11433880.html