import logging import time import humanize import datetime class Timing: __start: None __end: None __verbose: False __start_iso: None __end_iso: None def __init__(self, verbose: bool): self.__verbose = verbose def start(self): self.__start = time.time() self.__start_iso = datetime.datetime.now().isoformat() def end(self): self.__end = time.time() self.__end_iso = datetime.datetime.now().isoformat() def duration(self): delta = (self.__end - self.__start) return delta def get_duration(self): delta = humanize.precisedelta(self.duration(), minimum_unit="milliseconds") return f"time taken: {delta}" def print(self, action: str): info = humanize.precisedelta(self.duration(), minimum_unit="milliseconds") logging.info(f"{action} time taken: {info}") def get_start_iso(self): return self.__start_iso def get_end_iso(self): return self.__end_iso