from time import time as nt
class Timer(object):
def __init__(self):
self.starttime = 0.0 #开始时间
self.pauser = False #是否处于暂停状态
self.log1 = 0.0
self.pautime = 0.0 #暂停期间的时间
self.log2 = 0.0
def start(self): # 开始
self.starttime = nt()
def pause(self): #暂停
if not self.pauser:
self.log1 = nt()
self.pauser = True
def contin(self): #继续
if self.pauser:
self.pautime += nt() - self.log1
self.pauser = False
def time(self): #程序时间
if self.pauser:
return self.log1 - self.starttime - self.pautime
else:
return nt() - self.starttime - self.pautime
# 请多多指教
python计时器类
最新推荐文章于 2024-08-27 16:38:10 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)