[CONSTRUCTOR]
DurationBasic(
const fcf::NTest::DurationBasic::Options& a_options)
Class: fcf::NTest::DurationBasic
Package: fcfTest
File:
test.hpp
(
link_to_the_declaration_in_the_file
,
link_to_the_implementation_in_the_file
)
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 = 1
- Total number of iterations to perform.
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::milliseconds(100));
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::milliseconds(100));
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::microseconds(100));
});
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: 0.100125126
> Average: 0.100125126
> Working with the parameterized constructor
> Duration: 0.100111086
> Average: 0.000100111
> Working with the options constructor
> Duration: 0.158395148
> Average: 0.000158395
> |
> |
> |
> |
> |
> |
> |
> ||
> ||
> | | |||||||||||||||| | |
> ══════════════════════════════
> OX (value): [0.000`110`833 : 0.000`227`412]; Step: 3885.97
> OY (count): [0 : 678]; Step: 67.80
>
[SUCCESS] Test completed successfully (0.374`804`885 sec)
[SUCCESS] All tests were completed.
Tests: 1 passed, 0 failed, 0 skipped, 1 total
Duration: 0.374`804`885 sec