import time

class Timer:
    elapsed: float
    last_enabled: float
    enabled: bool

    def __init__(self):
        self.elapsed = 0.
        self.enabled = False

    def get_diff(self) -> float:
        if not self.enabled: return 0.
        return time.time() - self.last_enabled

    def start(self):
        if self.enabled: return
        self.enabled = True
        self.last_enabled = time.time()

    def stop(self):
        self.elapsed += self.get_diff()
        self.enabled = False

    def get_elapsed(self) -> float:
        return self.elapsed + self.get_diff()
    
    def reset(self):
        self.elapsed = 0.
        self.enabled = False
        self.last_enabled = 0.
