Type: int
Class: fcf::NTest::DurationBasic::BeginOptions
Package: fcfTest
File:
test.hpp
( link_to_the_declaration_in_the_file )
Available from version: 1.2.10
Enables or disables clock overhead correction during benchmarking.
The correction property controls whether the framework attempts to subtract the estimated overhead of the clock itself from the measurement results.
When benchmarking extremely fast operations (nanosecond scale), the act of calling the clock function and the framework's internal logic introduces a measurable delay. This property allows you to:
- If true (or non-zero): Enables correction. The framework performs a calibration phase to estimate the clock latency and subtracts it from the measured duration.
- If false (or zero): Disables correction. Measurements include all overhead.
- If -1 (default): Inherits the setting from the parent fcf::NTest::DurationBasic::Options object.
Example: Enabling Clock Overhead Correction
Demonstrating how to enable the correction feature to obtain more accurate results when measuring micro-operations.
#define FCF_TEST_IMPLEMENTATION
#include <fcfTest/test.hpp>
#include <iostream>
FCF_TEST_DEFINE("Benchmark", "Precision", "CorrectionTest") {
// 1. Configure options with correction enabled
fcf::NTest::Duration::Options options;
options.iterations = 1000;
// 2. Enable correction to subtract clock overhead
options.correction = 1;
// 3. Initialize benchmark
fcf::NTest::Duration bench(options);
// 4. Measure a very fast operation
bench([]() {
// A simple operation that takes very little time
volatile int x = 1 + 1;
});
// 5. Output results
fcf::NTest::log() << "Benchmark with correction completed." << std::endl;
fcf::NTest::log() << "Average: " << bench.average() << std::endl;
FCF_TEST(true);
}
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" -> "Precision" -> "CorrectionTest" ...
> Benchmark with correction completed.
> Average: 0.000000003
[SUCCESS] Test completed successfully (0.000`105`687 sec)
[SUCCESS] All tests were completed.
Tests: 1 passed, 0 failed, 0 skipped, 1 total
Duration: 0.000`105`687 sec
By setting correction to 1, the framework attempts to provide a cleaner measurement of the actual workload by compensating for the time spent in the timing infrastructure.