Source code for catalyst.tools.time_manager
"""
Simple timer.
"""
from time import time
[docs]class TimeManager(object):
"""@TODO: Docs. Contribution is welcome."""
[docs] def __init__(self):
"""Initialization"""
self._starts = {}
self.elapsed = {}
[docs] def start(self, name: str) -> None:
"""Starts timer ``name``.
Args:
name: name of a timer
"""
self._starts[name] = time()
[docs] def stop(self, name: str) -> None:
"""Stops timer ``name``.
Args:
name: 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"]