ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

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

2022-08-05 17:35:44  阅读:29  来源: 互联网

标签:timeSub 获取 python timeStart 耗时 key time consoleTimeDict


定义

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

专注分享技术,共同学习,共同进步。侵权联系[admin#icode9.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有