Mads
Multi-Agent Distributed System
Loading...
Searching...
No Matches
Mads::ExecutionTimeWindowStats Class Reference

Running window statistics for execution time samples. More...

#include <execution_time_window_stats.hpp>

Public Member Functions

 ExecutionTimeWindowStats (std::size_t window_width=100)
 Construct a statistics window with a maximum number of samples.
 
void tic ()
 Mark the start time of the next measured interval.
 
double toc ()
 Mark the stop time, compute elapsed time, and append it.
 
void set_window_width (std::size_t window_width)
 Set the running window width at runtime.
 
std::size_t window_width () const
 Get the current configured window width.
 
std::size_t size () const
 Get the number of currently stored samples.
 
double average_ms () const
 Get the arithmetic mean of stored samples.
 
double stddev_ms () const
 Get the population standard deviation of stored samples.
 
void clear ()
 Clear all stored samples and reset timing state.
 

Detailed Description

Running window statistics for execution time samples.

This header-only utility stores the latest execution durations (in milliseconds) up to a configurable window size and provides:

Typical usage:

stats.tic();
// ... code under test ...
double elapsed_ms = stats.toc();
Running window statistics for execution time samples.

Definition at line 38 of file execution_time_window_stats.hpp.

Constructor & Destructor Documentation

◆ ExecutionTimeWindowStats()

Mads::ExecutionTimeWindowStats::ExecutionTimeWindowStats ( std::size_t  window_width = 100)
inlineexplicit

Construct a statistics window with a maximum number of samples.

Parameters
window_widthMaximum number of latest samples retained.

Definition at line 45 of file execution_time_window_stats.hpp.

Member Function Documentation

◆ average_ms()

double Mads::ExecutionTimeWindowStats::average_ms ( ) const
inline

Get the arithmetic mean of stored samples.

Returns
Mean duration in milliseconds, or 0.0 when empty.

Definition at line 111 of file execution_time_window_stats.hpp.

◆ clear()

void Mads::ExecutionTimeWindowStats::clear ( )
inline

Clear all stored samples and reset timing state.

Definition at line 141 of file execution_time_window_stats.hpp.

◆ set_window_width()

void Mads::ExecutionTimeWindowStats::set_window_width ( std::size_t  window_width)
inline

Set the running window width at runtime.

If reduced, the oldest samples are dropped immediately. If increased, existing samples are preserved.

Parameters
window_widthNew maximum number of retained samples.

Definition at line 87 of file execution_time_window_stats.hpp.

References window_width().

◆ size()

std::size_t Mads::ExecutionTimeWindowStats::size ( ) const
inline

Get the number of currently stored samples.

Returns
Current sample count in the running window.

Definition at line 104 of file execution_time_window_stats.hpp.

◆ stddev_ms()

double Mads::ExecutionTimeWindowStats::stddev_ms ( ) const
inline

Get the population standard deviation of stored samples.

Uses:

\[
\sigma = \sqrt{E[x^2] - E[x]^2}
\]

Returns
Standard deviation in milliseconds, or 0.0 when empty.

Definition at line 128 of file execution_time_window_stats.hpp.

◆ tic()

void Mads::ExecutionTimeWindowStats::tic ( )
inline

Mark the start time of the next measured interval.

Call tic() before the code section you want to time, then call toc() to store the elapsed duration.

Definition at line 54 of file execution_time_window_stats.hpp.

◆ toc()

double Mads::ExecutionTimeWindowStats::toc ( )
inline

Mark the stop time, compute elapsed time, and append it.

If tic() was not called, this method returns 0.0 and does not append any sample.

Returns
Elapsed duration in milliseconds.

Definition at line 67 of file execution_time_window_stats.hpp.

◆ window_width()

std::size_t Mads::ExecutionTimeWindowStats::window_width ( ) const
inline

Get the current configured window width.

Returns
Maximum number of retained samples.

Definition at line 97 of file execution_time_window_stats.hpp.

Referenced by set_window_width().


The documentation for this class was generated from the following file: