Struct AverageTime
template <int _L>
Exponential moving average for smoothing time-series data. More...
#include <structs.h>
Public Attributes
| Type | Name |
|---|---|
| float | result = 0Current average value. |
Public Functions
| Type | Name |
|---|---|
| void | Update (float _rate) Update average with new sample. |
Detailed Description
AverageTime computes exponentially-weighted moving average (EWMA) to smooth noisy measurements like frame times or FPS. More recent values are weighted higher than older values.
Algorithm: * New average = Old average + (New sample - Old average) / Window size * Equivalent to EWMA with alpha = 1 / _L
Mathematical Properties: * Larger _L = slower response, smoother output * Smaller _L = faster response, more noise * Typical _L for FPS smoothing: 30-120 samples
Template parameters:
_LWindow size (number of samples for smoothing)
Note:
Does not store sample history - constant memory usage.
Note:
Not thread-safe - use per-thread instances if needed.
Public Attributes Documentation
variable result
Current average value.
float AverageTime< _L >::result;
Public Functions Documentation
function Update
Update average with new sample.
inline void AverageTime::Update (
float _rate
)
Incorporates new measurement into exponential moving average. Result converges to stable value after approximately _L samples.
Parameters:
_rateNew sample value to incorporate
Note:
First _L samples have reduced accuracy (startup transient).
Note:
Can be called with any numeric type (implicitly converts to float).
Example:
AverageTime<60> fps_avg; // 60-sample window
while (running) {
float frame_time = MeasureFrameTime();
fps_avg.Update(1.0f / frame_time);
DisplayFPS(fps_avg.result); // Smoothed FPS value
}
The documentation for this class was generated from the following file src/extra/structs.h