编程语言
首页 > 编程语言> > python计算耗时,可多次获取耗时

python计算耗时,可多次获取耗时

作者:互联网

定义

consoleTimeDict = {"默认": 0}


def consoleTime(key="默认"):
    timeStart = time.time()
    consoleTimeDict[key] = timeStart
    return timeStart


def consoleTimeEnd(key="默认"):
    timeStart = consoleTimeDict[key]
    timeEnd = time.time()
    timeSub = timeEnd - timeStart
    print("{} 耗时: {:.3f}秒".format(key, timeSub))
    return timeSub

使用

consoleTime()
JoinVideo()
consoleTimeEnd()

结果

默认 耗时: 24.006秒

本文地址

 https://www.cnblogs.com/stumpx/p/16555127.html

标签:timeSub,获取,python,timeStart,耗时,key,time,consoleTimeDict
来源: https://www.cnblogs.com/stumpx/p/16555127.html