Simple block-based timers using Welford's Online Algorithm to approximate
mean and variance.
Usage:
timer = TimedBlock()
for _ in range(10):
with timer():
sleep(1)
print(time.sleep())
# (1.000013, 1.3e-5)
## Classes
### `class StatisticsAccumulator(ABC):`
<div style="padding-left: 20px;">
Interface for a statistics integrator.
#### Methods
```python
def add(self, value) -> None
Add the value
to the running statistics.
Arguments:
value(float)
: the sample to integrate
def current(self) -> Tuple[float, float]
Returns the statistics of the observed samples so far.
Returns:
Implements Welford's Online Algorithm for single-pass variance and
mean.
-
count
: int
= 0
-
mean
: float
= 0.0
-
differences
: float
= 0.0
def add(self, value) -> None
Add the value
to the running statistics.
Arguments:
value(float)
: the sample to integrate
def current(self) -> Tuple[float, float]
Returns the current values of the Welford algorithm.
Returns:
values
: deque
= field(default_factory=lambda : deque(maxlen=100))
def add(self, value) -> None
Add the value
to the running statistics.
Arguments:
value(float)
: the sample to integrate
def current(self) -> Tuple[float, float]
Returns the current statistics.
Returns:
Used to track the performance statistics of a block of code, in terms of
execution time.
def __init__(self, tracker_type) -> None
Create a new timed block instance.
Arguments:
tracker_type(Type[StatisticsAccumulator])
: The statistics integrator to use. Defaults
to to MovingWindowStats
def mean(self) -> float
Retrieve the mean execution time.
def var(self) -> None
Retrieve the variance of the execution time.
def stats(self) -> None
Retrieve the mean and the variance of execution time.