Skip to content

proxystore.utils.timer

Timing utilities.

Timer

Timer()

Performance timer with nanosecond precision.

Example
from proxystore.timer import Timer

with Timer() as timer:
    ...

print(timer.elapsed_ms)
Example
from proxystore.timer import Timer

timer = Timer()
timer.start()
...
timer.stop()

print(timer.elapsed_ms)

Raises:

  • RuntimeError

    If the elapsed time is accessed before the timer is stopped or the context block is exited.

Source code in proxystore/utils/timer.py
def __init__(self) -> None:
    self._start = 0
    self._end = 0
    self._running = False

elapsed_ns property

elapsed_ns: int

Elapsed time in nanoseconds.

elapsed_ms property

elapsed_ms: float

Elapsed time in milliseconds.

elapsed_s property

elapsed_s: float

Elapsed time in seconds.

start

start() -> Self

Start the timer.

Source code in proxystore/utils/timer.py
def start(self) -> Self:
    """Start the timer."""
    self._running = True
    self._start = time.perf_counter_ns()
    return self

stop

stop() -> Self

Stop the timer.

Source code in proxystore/utils/timer.py
def stop(self) -> Self:
    """Stop the timer."""
    self._end = time.perf_counter_ns()
    self._running = False
    return self