Type:
class fcf::NTest::DurationBasic::BeginOptions
Owner class: fcf::NTest::DurationBasic
Package: fcfTest
File:
test.hpp
( link_to_the_text_position_in_the_file )
Available from version: 1.2.5
A configuration structure used to define the initial parameters for a measurement session in the DurationBasic class, such as iteration count and histogram resolution.
The fcf::NTest::DurationBasic::BeginOptions structure is used to specify the execution parameters when starting a measurement session via the begin method.
This structure allows you to specify the number of measured iterations, as well as the dimension of the histogram for statistical analysis.
It contains two primary configuration members:
- iterations: The total number of iterations to perform. A value of -1 indicates that the default iterations from the parent DurationBasic object should be used.
- histogramBins: The number of bins for the histogram. A value of -1 indicates that the size will be determined automatically.
Properties
- The number of times the measurement loop should be executed to collect statistical data.
- The number of bins to use for the duration histogram.
Example: Customizing Measurement Session
Demonstrates how to create BeginOptions to specify a custom number of iterations and a fixed number of histogram bins for a benchmarking session.
#define FCF_TEST_IMPLEMENTATION
#include <fcfTest/test.hpp>
FCF_TEST_DEFINE("Benchmark", "Options", "BeginOptionsDemo"){
// 1. Initialize the Duration object with default settings
fcf::NTest::Duration bench;
// 2. Create custom BeginOptions
// We want to run 5000 iterations and use 20 bins for the histogram
fcf::NTest::Duration::BeginOptions options(5000, 20);
// 3. Start the measurement session using the custom options
// The begin method accepts BeginOptions to override the default behavior
bench.begin(options);
// 4. Execute the code to be measured
for(volatile int i = 0; i < options.iterations; ++i) {
// Code to benchmark
volatile int a = i * 2;
volatile int b = a + 10;
FCF_TEST(a + 10 == b, b);
}
// 5. End the measurement session
bench.end();
// 6. Log the results
fcf::NTest::log() << "Avg duration: " << bench.average() << std::endl;
fcf::NTest::log() << "Histogram bins used: " << bench.histogram().size() << 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:
erforming the test: "Benchmark" -> "Options" -> "BeginOptionsDemo" ...
> Avg duration: 0.000000002
> Histogram bins used: 10
[SUCCESS] Test completed successfully (0.000`035`384 sec)
[SUCCESS] All tests were completed.
Tests: 1 passed, 0 failed, 0 skipped, 1 total
Duration: 0.000`035`384 sec