import time
def set_func(func):
def call_func(*args, **kwargs):
start_time = time.time()
func(*args, **kwargs)
end_time = time.time()
print('use time:%i' % int(end_time - start_time))
return call_func
@set_func
def sss():
time.sleep(4.0)
if __name__ == '__main__':
sss()
结果:
use time:4