pyuutils.base.time

TimeMonitor

class pyuutils.base.time.TimeMonitor(period_in_seconds: float = 1.0)[source]

Monitors time periods based on event counts.

This class provides an efficient way to track events and rates over time, minimizing the number of system clock queries.

__init__(period_in_seconds: float = 1.0)[source]

Initialize the TimeMonitor.

Parameters:

period_in_seconds (float) – The period to monitor in seconds

event_rate() int[source]

Compute the number of events per second.

Returns:

Event rate

Return type:

int

get_events() int[source]

Get the number of events registered for the current period.

Returns:

Number of events

Return type:

int

has_passed() bool[source]

Account for an event and check if the specified time period has passed.

Returns:

True if the period has passed, False otherwise

Return type:

bool

next() None[source]

Prepare for the next period.

reset() None[source]

Reset the monitor for another/unrelated performance measure.