Python 巧用time模块计算函数的执行所需时间
程序员文章站
2022-05-05 15:09:49
...
#用装饰器demo演示
import time
def set_fun(func):
def call_fun(*args, **kwargs):
first_time = time.time()
func_exec = func(*args, **kwargs)
print(time.time() - first_time)
return func_exec
return call_fun
@set_fun
def test():
print("test")
time.sleep(1)
test()