Shortcuts

Source code for catalyst.utils.tools.time_manager

"""
Simple timer.
"""
from time import time


[docs]class TimeManager(object): """@TODO: Docs. Contribution is welcome."""
[docs] def __init__(self): """@TODO: Docs. Contribution is welcome.""" self._starts = {} self.elapsed = {}
[docs] def start(self, name: str) -> None: """Starts timer ``name``. Args: name (str): name of a timer """ self._starts[name] = time()
[docs] def stop(self, name: str) -> None: """Stops timer ``name``. Args: name (str): name of a timer """ assert name in self._starts, f"Timer '{name}' wasn't started" self.elapsed[name] = time() - self._starts[name] del self._starts[name]
[docs] def reset(self) -> None: """Reset all previous timers.""" self.elapsed = {} self._starts = {}
__all__ = ["TimeManager"]