FCF 2.0 development in progress...
> > > > > >
[News] [C++ Libraries API] [C++ Downloads] [Donate to the project] [Contacts]

Options class
From fcf::NTest::DurationBasic class

Type:
class fcf::NTest::DurationBasic::Options

Owner class: fcf::NTest::DurationBasic

Base class: fcf::NTest::DurationBasic::BeginOptions

Package: fcfTest

File: test.hpp ( link_to_the_text_position_in_the_file )

Available from version: 1.2.5

An extended configuration structure for benchmarking sessions, providing fine-grained control over iterations, warmup, measurement steps, and histogram resolution.

The fcf::NTest::DurationBasic::Options structure provides comprehensive configuration for a benchmarking session. It inherits from fcf::NTest::DurationBasic::BeginOptions and adds advanced parameters to improve measurement accuracy and statistical depth. Key features include:

  • measurementStep: Defines the interval at which timing data is sampled and added to the histogram.
  • warmup: Specifies the number of initial iterations to perform to stabilize the environment (e.g., CPU cache, JIT) before actual measurements begin.
  • iterations: The total number of iterations to perform.
  • histogramBins: Controls the granularity of the statistical distribution.

This structure is typically passed to operator() of the fcf::NTest::DurationBasic class or to its constructor to perform a controlled benchmark.

If a class property is less than 0, the default value is used.

For the fcf::NTest::BasicDuration class, if a value is not set in the constructor, the fields use the following values:

  • iterations = 1
  • histogramBins = 10
  • measurementStep = 1
  • warmup = 0

Properties
size_t measurementStep = -1
- The number of iterations to skip between consecutive measurements.
size_t warmup = -1
- The number of initial iterations to perform before starting actual measurements.

Example: Advanced Benchmarking Configuration

Demonstrates how to use the full Options structure to perform a benchmark with warmup iterations and periodic sampling for high-precision statistical analysis.

#define FCF_TEST_IMPLEMENTATION #include <fcfTest/test.hpp> FCF_TEST_DEFINE("Benchmark", "Advanced", "FullOptionsDemo"){ // 1. Define advanced options // We want: 10,000 total iterations, 20 histogram bins, // 100 warmup iterations, and sampling every 100 iterations. fcf::NTest::Duration::Options options(10000, 20, 100, 100); // 2. Initialize the Duration object fcf::NTest::Duration bench(options); // 3. Execute the benchmark using the options object // The operator() will handle warmup, iterations, and sampling automatically. bench([]() { // The code to be measured std::vector<int> v(100, 42); std::sort(v.begin(), v.end()); }); // 4. Log the detailed results fcf::NTest::log() << "--- Benchmark Results ---" << std::endl; fcf::NTest::log() << "Avg: " << bench.average() << std::endl; fcf::NTest::log() << "Min: " << bench.min() << std::endl; fcf::NTest::log() << "Max: " << bench.max() << std::endl; fcf::NTest::log() << "Median: " << bench.median() << std::endl; fcf::NTest::log() << "\n--- Distribution ---\n" << bench.histogram().toBarChart(40, 10) << std::endl; } int main(int a_argc, char* a_argv[]) { bool error = false; fcf::NTest::cmdRun(a_argc, a_argv, fcf::NTest::CRM_RUN, &error); return error ? 1 : 0; }

Output:

Performing the test: "Benchmark" -> "Advanced" -> "FullOptionsDemo" ... > --- Benchmark Results --- > Avg: 0.000005161 > Min: 0.000004739 > Max: 0.000005646 > Median: 0.000005140 > > --- Distribution --- > ||| > |||| > ||||||| > ||||||||| > ||||||||| | > ||||||||||||| | > |||||||||||||| ||| > |||||||||||||||||||| || > |||||| ||||||||||||||||||||| |||| > |||||||||||||||||||||||||||||||| |||||| > ════════════════════════════════════════ > OX (value): [0.000`004`739 : 0.000`005`646]; Step: 22.68 > OY (count): [1 : 728]; Step: 72.70 > [SUCCESS] Test completed successfully (0.052`257`782 sec) [SUCCESS] All tests were completed. Tests: 1 passed, 0 failed, 0 skipped, 1 total Duration: 0.052`257`782 sec