python 装饰器计算函数耗时

装饰器计算函数耗时:

def clock(func):
    "用于计算函数耗时的装饰器"
    def funCountTime(*args, **kwargs):
        startTime = time.time()
        result = func(*args, **kwargs)
        endTime = time.time()
        timeCost = endTime - startTime
        print(f'func<{func.__name__}> timeCost: {timeCost} s')
        return result
    return funCountTime

 

上一篇:Django(47)drf请求生命周期分析


下一篇:httpx_send_file