代码示例
import time import logging logging.basicConfig(level=logging.DEBUG) def timer(func): """ 函数执行计时器 """ def inner(*args, **kwargs): start = time.time() ret = func(*args, **kwargs) end = time.time() logging.info("time: {:.2f} s".format(end - start)) return ret return inner
使用方式
@timer def function(): pass function()