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

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

[CONSTRUCTOR] DurationBasic()
[CONSTRUCTOR] DurationBasic(unsigned long long a_iterationCount, unsigned long long a_measurementStep = 1, unsigned long long a_warmupCount = 0)
[CONSTRUCTOR] DurationBasic(const fcf::NTest::DurationBasic::Options& a_options)

Class: fcf::NTest::DurationBasic

Package: fcfTest

File: test.hpp

Available from version: 1.2.5

Initializes a new benchmarking session with specified iteration and measurement parameters.

The constructor initializes the benchmarking object. Depending on the arguments provided, it sets up the total number of iterations, the step size for measurements, and the number of warmup iterations.

There are three available ways to initialize the object:

  • Default Constructor: Initializes with 1 iteration, 1 measurement step, and 0 warmup iterations.
  • Basic Parameter Constructor: Allows setting total iterations, measurement step, and warmup count.
  • Options Constructor: Uses a fcf::NTest::DurationBasic::Options structure for full configuration.

Arguments

unsigned long long a_iterationCount
- Total number of iterations to perform.

unsigned long long a_measurementStep = 1
- Number of iterations per measurement step. Used when an iteration is short in duration; the measurement is based on the average value of N iterations.

unsigned long long a_warmupCount = 0
- Number of warmup iterations before actual measurement.

fcf::NTest::DurationBasic::Options& a_options
- Configuration options structure.

Example: Initializing DurationBasic

Demonstrating different ways to instantiate the DurationBasic class.

#define FCF_TEST_IMPLEMENTATION #include <fcfTest/test.hpp> #include <thread> #include <chrono> FCF_TEST_DEFINE("BenchDemo", "Duration", "ConstructorTest") { // 1. Default constructor fcf::NTest::Duration benchDefault; benchDefault.begin(); std::this_thread::sleep_for(std::chrono::seconds(1)); benchDefault.end(); fcf::NTest::log() << "Working with the default constructor" << std::endl; fcf::NTest::log() << " Duration: " << benchDefault.duration() << std::endl; fcf::NTest::log() << " Average: " << benchDefault.average() << std::endl; // 2. Parameterized constructor fcf::NTest::Duration benchParam(1000); benchParam.begin(); std::this_thread::sleep_for(std::chrono::seconds(1)); benchParam.end(); fcf::NTest::log() << "Working with the parameterized constructor" << std::endl; fcf::NTest::log() << " Duration: " << benchParam.duration() << std::endl; fcf::NTest::log() << " Average: " << benchParam.average() << std::endl; // 3. Options constructor fcf::NTest::Duration::Options opts; opts.iterations = 1000; opts.histogramBins = 30; opts.warmup = 100; fcf::NTest::Duration benchOpts(opts); benchOpts([](){ std::this_thread::sleep_for(std::chrono::milliseconds(1)); }); fcf::NTest::log() << "Working with the options constructor" << std::endl; fcf::NTest::log() << " Duration: " << benchOpts.duration() << std::endl; fcf::NTest::log() << " Average: " << benchOpts.average() << std::endl; fcf::NTest::log() << benchOpts.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: "BenchDemo" -> "Duration" -> "ConstructorTest" ... > Working with the default constructor > Duration: 1.000131645 > Average: 1.000131645 > Working with the parameterized constructor > Duration: 1.000106264 > Average: 0.001000106 > Working with the options constructor > Duration: 1.094068145 > Average: 0.001094068 > | > | > | | > || || > || || | > ||| | ||||| > |||| | ||||| > ||||||||||||| > |||||||||||||| > | |||||||||||||||||||||||| ||| > ══════════════════════════════ > OX (value): [0.001`018`615 : 0.001`175`142]; Step: 5217.57 > OY (count): [0 : 140]; Step: 14.00 > [SUCCESS] Test completed successfully (3.203`323`129 sec) [SUCCESS] All tests were completed. Tests: 1 passed, 0 failed, 0 skipped, 1 total Duration: 3.203`323`129 sec