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

iterations from class fcf::NTest::DurationBasic::BeginOptions

Property: iterations = -1

Type: size_t

Class: fcf::NTest::DurationBasic::BeginOptions

Package: fcfTest

File: test.hpp ( link_to_the_declaration_in_the_file )

Available from version: 1.2.5

The number of times the measurement loop should be executed to collect statistical data.

The iterations property specifies how many times the provided callable (lambda or function) should be invoked during the measurement phase. This is used to perform multiple measurements to calculate reliable statistics such as average, minimum, maximum, and to populate the histogram.

If a negative value is passed, the values ​​set on the object itself or the default values ​​are used.

For the begin and end blocks, this property indicates how many iterations were performed between these calls.

When measuring repetitive operations, this property indicates how many times the operation should be repeated.

Example: Performing a single operation split into multiple iterations.

Demonstrating how to use iterations to run a workload multiple times and collect timing data.

#define FCF_TEST_IMPLEMENTATION #include <fcfTest/test.hpp> #include <iostream> #include <thread> #include <chrono> // A simple workload that simulates processing time void simulate_work() { std::this_thread::sleep_for(std::chrono::milliseconds(1)); } FCF_TEST_DEFINE("DurationDemo", "Statistics", "MultipleIterations") { // 1. Create an instance of fcf::NTest::DurationBasic using a steady clock fcf::NTest::Duration duration; // 2. Configure the BeginOptions fcf::NTest::Duration::BeginOptions options; // We want to run the workload 50 times to get a good distribution options.iterations = 50; // 3. Start the measurement with the configured options // The duration object will execute the lambda 50 times duration.begin(options, 0); for(long long i = 0; i < options.iterations; ++i) { simulate_work(); } // 4. End the measurement duration.end(0, -1); // 5. Output the collected statistics fcf::NTest::log() << "Duration: " << duration.duration().str(true) << " sec" << std::endl; fcf::NTest::log() << "Average duration: " << duration.average().str(true) << " sec" << 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: "DurationDemo" -> "Statistics" -> "MultipleIterations" ... > Duration: 0.054`612`395 sec > Average duration: 0.001`092`247 sec [SUCCESS] Test completed successfully (0.054`689`092 sec) [SUCCESS] All tests were completed. Tests: 1 passed, 0 failed, 0 skipped, 1 total Duration: 0.054`689`092 sec

Example: Performing multiple iterations

#define FCF_TEST_IMPLEMENTATION #include <fcfTest/test.hpp> #include <iostream> #include <thread> #include <chrono> // A simple workload that simulates processing time void simulate_work() { std::this_thread::sleep_for(std::chrono::milliseconds(1)); } FCF_TEST_DEFINE("DurationDemo", "Statistics", "MultipleIterations") { // 1. Create an instance of fcf::NTest::DurationBasic using a steady clock fcf::NTest::Duration duration; // 2. Configure the Options. // This object inherits from the BeginOptions class. fcf::NTest::Duration::Options options; // We want to run the workload 50 times to get a good distribution options.iterations = 50; // 3. Execute the code 50 times duration(options, [](){ simulate_work(); }); // 4. Output the collected statistics fcf::NTest::log() << "Duration: " << duration.duration().str(true) << " sec" << std::endl; fcf::NTest::log() << "Average duration: " << duration.average().str(true) << " sec" << std::endl; fcf::NTest::log() << "Min duration: " << duration.min().str(true) << " sec" << std::endl; fcf::NTest::log() << "Max duration: " << duration.max().str(true) << " sec" << std::endl; fcf::NTest::log() << duration.histogram().toBarChart() << 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: "DurationDemo" -> "Statistics" -> "MultipleIterations" ... > Duration: 0.054`570`981 sec > Average duration: 0.001`091`419 sec > Min duration: 0.001`050`769 sec > Max duration: 0.001`128`673 sec > | > | > | | > | | > | | | > | | | > | | ||| > | | ||| > |||| |||| > ||||||||| > ══════════ > OX (value): [0.001`050`769 : 0.001`128`673]; Step: 7790.40 > OY (count): [1 : 12]; Step: 1.10 > [SUCCESS] Test completed successfully (0.054`822`424 sec) [SUCCESS] All tests were completed. Tests: 1 passed, 0 failed, 0 skipped, 1 total Duration: 0.054`822`424 sec