关心编写定义的某一个恶函数执行的用时问题
import time
from functools import wraps
def func_timer(function):
'''
用装饰器实现函数计时
:param function: 需要计时的函数
:return: None
'''
@wraps(function)
def function_timer(*args, **kwargs):
print('[Function: 开始执行程序')
t0 = time.time()
result = function(*args, **kwargs)
t1 = time.time()
print('[Function: 执行完成, 耗时: {time:.2f}s]'.format(time=t1 - t0))
return result
return function_timer
@func_timer
def cui():
print('kaishi11111')
time.sleep(4)
print('woaini')
cui()
python程序计时装饰器 - 知乎 (zhihu.com)