8#include "../global.hpp"
9#include "utilities.hpp"
10#include "stop_watch.hpp"
57 return std::make_unique<RateCounter>(windowSize);
69 return std::make_unique<RateCounter>(windowSize, mode);
88 , windowSize_(windowSize)
101 , windowSize_(windowSize)
122 return stopWatch_.
Mode();
143 if (windowSize_ == windowSize)
149 windowSize_ = windowSize;
151 while (
static_cast<int>(measurements_.size()) > windowSize_)
152 measurements_.pop_front();
165 double sum = std::accumulate(measurements_.begin(), measurements_.end(), 0.0);
166 if (!measurements_.size())
169 auto result = std::round(sum /
static_cast<double>(measurements_.size()));
181 if (measurements_.size() < 2)
185 return 1000.0 /
static_cast<double>(averageTimeSpan.count());
205 measurements_.clear();
216 if (std::isnan(lastReading_))
223 auto now =
static_cast<double>(stopWatch_.
TimeSpan().count());
224 measurements_.push_back(now - lastReading_);
228 while (
static_cast<int>(measurements_.size()) > windowSize_)
229 measurements_.pop_front();
Frame rate measurement counter with selectable averaging window.
Definition: rate_counter.hpp:25
RateCounter(int windowSize, StopWatchMode mode)
Constructor for a rate counter object.
Definition: rate_counter.hpp:99
static constexpr int MinimumWindowSize
Minimal selectable averaging window size.Trying to select a smaller window will result in an exceptio...
Definition: rate_counter.hpp:31
std::chrono::milliseconds AverageTimeSpan() const noexcept
Average time span between two steps or since the creation of the counter or the most recent reset.
Definition: rate_counter.hpp:163
void SetWindowSize(int windowSize)
Sets the currently used averaging window size.
Definition: rate_counter.hpp:141
static std::unique_ptr< RateCounter > Create(int windowSize)
Creates a frame counter object for multi CPU.
Definition: rate_counter.hpp:55
void Reset() noexcept
Erase all measurements so far.
Definition: rate_counter.hpp:203
static std::unique_ptr< RateCounter > Create()
Creates a frame counter object for multi CPU with default averaging window (25).
Definition: rate_counter.hpp:44
double Rate() const noexcept
Returns the rate(1 / s) at which the steps occurred.
Definition: rate_counter.hpp:179
int NumSteps() const noexcept
Number of steps called since construction or since last reset.
Definition: rate_counter.hpp:194
static constexpr int MaximumWindowSize
Maximum selectable averaging window size. Trying to select a larger window will result in an exceptio...
Definition: rate_counter.hpp:37
void Step() noexcept
Reading step (first reading step will not yield a measurement result, but define the starting point).
Definition: rate_counter.hpp:214
RateCounter()
Constructor for a rate counter object for multi-CPU architectures with default averaging window size ...
Definition: rate_counter.hpp:76
int WindowSize() const noexcept
Gets the currently used averaging window size.
Definition: rate_counter.hpp:130
static std::unique_ptr< RateCounter > Create(int windowSize, StopWatchMode mode)
Creates a frame counter object.
Definition: rate_counter.hpp:67
static constexpr int DefaultWindowSize
Default averaging window size.
Definition: rate_counter.hpp:34
StopWatchMode Mode() const noexcept
The stop watch mode used internally.
Definition: rate_counter.hpp:120
RateCounter(int windowSize)
Constructor for a rate counter object for multi-CPU architectures.
Definition: rate_counter.hpp:86
Speed measurement object.
Definition: stop_watch.hpp:47
void Start()
Start (or re-start) the stopwatch.
Definition: stop_watch.hpp:136
std::chrono::milliseconds TimeSpan() const
Gets the time, that has elapsed since start (or since the construction of the object,...
Definition: stop_watch.hpp:147
StopWatchMode Mode() const noexcept
Mode for which the stop watch was created.
Definition: stop_watch.hpp:160
StopWatchMode
Mode at which the StopWatch should work.
Definition: utilities.hpp:31
Root namespace for the Image Manager interface.
Definition: c_barcode.h:15