import time class Timer: def __init__(self): self.start_time = 0 self.end_time = 0 self.elapsing = False def start(self): if(self.elapsing): return self.start_time = time.time() self.elapsing = True def stop(self): if(not self.elapsing): return self.end_time = time.time() self.elapsing = False def elapsed_time(self): if(self.elapsing): return (str)(round(time.time() - self.start_time, 3)) + " seconds" return (str)(round(self.end_time - self.start_time, 3)) + " seconds" def reset(self): self.start_time = 0 self.end_time = 0 self.elapsing = False