python计算耗时,可多次获取耗时
定义
sinceTimeDict = {"默认": 0} def sinceTime(key="默认"): timeStart = time.time() sinceTimeDict[key] = timeStart return timeStart def sinceTimeEnd(key="默认"): timeStart = sinceTimeDict[key] timeEnd = time.time() timeSub = timeEnd - timeStart print("{} 耗时: {:.3f}秒".format(key, timeSub)) return timeSub
使用
sinceTime()
JoinVideo()
sinceTimeEnd()
结果
默认 耗时: 24.006秒
本文地址
https://www.cnblogs.com/stumpx/p/16555127.html