Type: size_t
Class: fcf::NTest::DurationBasic::Options
Package: fcfTest
File:
test.hpp
( link_to_the_declaration_in_the_file )
Available from version: 1.2.5
The number of initial iterations to perform before starting actual measurements.
The warmup property specifies the number of initial iterations that should be executed to prepare the system (e.g., CPU cache warming, JIT compilation, or memory allocation) before the actual timing measurements begin.
Using a warmup phase is crucial for microbenchmarking to ensure that the measured results are not skewed by the initial overhead of the environment or the first-time execution of the code under test.
Example: Using Warmup to Stabilize Measurements
Demonstrating how to use warmup to ensure the system is in a steady state before recording data.
#define FCF_TEST_IMPLEMENTATION
#include <fcfTest/test.hpp>
#include <iostream>
#include <thread>
#include <chrono>
void simulate_work() {
std::this_thread::sleep_for(std::chrono::milliseconds(2));
}
FCF_TEST_DEFINE("WarmupDemo", "Options", "WarmupPhase") {
// 1. Configure the Options
fcf::NTest::Duration::Options options;
// Total iterations to be measured
options.iterations = 50;
// Perform 20 warmup iterations first
options.warmup = 20;
fcf::NTest::Duration duration(options);
// 2. Execute workload and measurement
duration([](){
simulate_work();
});
// 3. Output results
fcf::NTest::log() << "Average duration (after warmup): " << duration.average() << " sec" << 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: "WarmupDemo" -> "Options" -> "WarmupPhase" ...
> Average duration (after warmup): 0.002107449 sec
[SUCCESS] Test completed successfully (0.147`354`475 sec)
[SUCCESS] All tests were completed.
Tests: 1 passed, 0 failed, 0 skipped, 1 total
Duration: 0.147`354`475 sec