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

options() method from fcf::NTest::DurationBasic class

fcf::NTest::DurationBasic<TClock>::Options options() const
void options(fcf::NTest::DurationBasic<TClock>::Options a_options)

Class: fcf::NTest::DurationBasic

Package: fcfTest

File: test.hpp

Available from version: 1.2.5

Provides access to or updates the current measurement options for the benchmarking session.

The options method allows you to manage the configuration of a benchmarking session.

Depending on the signature used, it performs one of two roles:

  • Read Mode: When called without arguments, it returns a copy of the current fcf::NTest::DurationBasic::Options object. This is useful for inspecting the current configuration before making changes.
  • Write Mode: When called with an fcf::NTest::DurationBasic::Options object as an argument, it updates the internal configuration. During this process, the method ensures that all parameters (such as iterations, warmup, and histogram bins) are validated and clamped to their minimum valid values.

Arguments

fcf::NTest::DurationBasic<TClock>::Options a_options
- The new configuration for the measurement session.
Result
fcf::NTest::DurationBasic<TClock>::Options
- A copy of the current measurement options.

Example: Reading and Updating Benchmarking Options

Demonstrating how to retrieve the current configuration, modify its parameters, and apply the new settings to the benchmarking object.

#define FCF_TEST_IMPLEMENTATION #include <fcfTest/test.hpp> #include <iostream> FCF_TEST_DEFINE("OptionsDemo", "Benchmarking", "OptionsAccess") { // Create a duration object with default options fcf::NTest::Duration bench(100, 1, 0); // 1. Retrieve current options (Read Mode) fcf::NTest::Duration::Options currentOptions = bench.options(); std::cout << "Current iterations: " << currentOptions.iterations << std::endl; // 2. Modify options currentOptions.iterations = 500; currentOptions.warmup = 10; currentOptions.histogramBins = 20; // 3. Apply new options (Write Mode) bench.options(currentOptions); // 4. Verify the change fcf::NTest::Duration::Options updatedOptions = bench.options(); std::cout << "Updated iterations: " << updatedOptions.iterations << std::endl; std::cout << "Updated warmup: " << updatedOptions.warmup << std::endl; // Perform a quick benchmark with the new settings bench([](){ int x = 0; for(int i=0; i<100; ++i) x++; }); fcf::NTest::log() << "Benchmark completed with new options." << 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: "OptionsDemo" -> "Benchmarking" -> "OptionsAccess" ... Current iterations: 100 Updated iterations: 500 Updated warmup: 10 > Benchmark completed with new options. [SUCCESS] Test completed successfully (0.000`422`932 sec) [SUCCESS] All tests were completed. Tests: 1 passed, 0 failed, 0 skipped, 1 total Duration: 0.000`422`932 sec

The options method is essential for fine-tuning benchmark parameters like iteration count and warmup cycles during runtime.