void
begin(
int a_beginLevel
= 0)
void
begin(
int a_beginLevel,
int a_endLevel)
void
begin(
const fcf::NTest::DurationBasic::BeginOptions& a_options,
int a_beginLevel
= 0)
void
begin(
const fcf::NTest::DurationBasic::BeginOptions& a_options,
int a_beginLevel,
int a_endLevel)
Class: fcf::NTest::DurationBasic
Package: fcfTest
File:
test.hpp
Available from version: 1.2.5
Starts a measurement session at a specific level.
The begin method marks the starting point for a measurement. It can be used to start a single measurement or a range of measurement levels.
Each fcf::NTest::DurationBasic object can store multiple duration measurements, allowing a single object to perform measurements across unrelated processes or to perform nested duration measurements within internal code blocks. The stored measurements are called levels.
When performing a measurement with the begin and end methods, the object assumes it is performing N iterations at once, as specified in fcf::NTest::DurationBasic::Options::iterations in the object configuration or as defined individually for the called method via fcf::NTest::DurationBasic::BeginOptions::iterations.
Depending on the signature, it behaves as follows:
- Single Level: Starts a measurement for a single level index.
- Level Range: Starts measurements for all levels from a_beginLevel up to (but not including) a_endLevel.
- With Options: Starts a measurement using specific fcf::NTest::DurationBasic::BeginOptions.
Arguments
fcf::NTest::DurationBasic::BeginOptions& a_options
- The options to use for this measurement session.
int a_beginLevel
- The starting level index for measurement.
int a_endLevel
- The ending level index (exclusive). If the value is less than 0, all reserved levels following a_beginLevel will be included. Levels can be reserved using the reset, begin, and end methods.
Example: Starting a Measurement
Demonstrating how to start a measurement for a specific level.
#define FCF_TEST_IMPLEMENTATION
#include <fcfTest/test.hpp>
#include <thread>
#include <chrono>
FCF_TEST_DEFINE("Bench", "Level", "BeginTest") {
fcf::NTest::Duration bench(100);
// Start measurement at level 0
bench.begin(0);
// Perform work
std::this_thread::sleep_for(std::chrono::seconds(1));
bench.end(0);
fcf::NTest::log() << "Measurement finished." << std::endl;
fcf::NTest::log() << " Duration: " << bench.duration(0) << 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: "Bench" -> "Level" -> "BeginTest" ...
> Measurement finished.
> Duration: 1.000090518
[SUCCESS] Test completed successfully (1.000`143`731 sec)
[SUCCESS] All tests were completed.
Tests: 1 passed, 0 failed, 0 skipped, 1 total
Duration: 1.000`143`731 sec
Example: Example with nested measurement levels
#define FCF_TEST_IMPLEMENTATION
#include <fcfTest/test.hpp>
#include <thread>
#include <chrono>
FCF_TEST_DEFINE("Bench", "Level", "BeginTest") {
fcf::NTest::Duration bench(100);
// Perform multiple runs of the measured code block
bench([&](){
std::this_thread::sleep_for(std::chrono::milliseconds(1));
{
bench.begin(
// Explicitly specify that we are measuring only one iteration
// because the Duration object is initialized with
// Duration::Options::iterations equal to 100
fcf::NTest::Duration::BeginOptions{1},
// Set that the measurement will be performed at level 1
1
);
std::this_thread::sleep_for(std::chrono::milliseconds(1));
bench.end(1);
}
std::this_thread::sleep_for(std::chrono::milliseconds(1));
});
fcf::NTest::log() << "Measurement finished." << std::endl;
fcf::NTest::log() << " Duration [0]: " << bench.duration(0) << std::endl;
fcf::NTest::log() << " Average [0]: " << bench.average(0) << std::endl;
fcf::NTest::log() << " Duration [1]: " << bench.duration(1) << std::endl;
fcf::NTest::log() << " Average [1]: " << bench.average(1) << 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: "Bench" -> "Level" -> "BeginTest" ...
> Measurement finished.
> Duration [0]: 0.326836493
> Average [0]: 0.003268364
> Duration [1]: 0.109027752
> Average [1]: 0.001090277
[SUCCESS] Test completed successfully (0.326`943`583 sec)
[SUCCESS] All tests were completed.
Tests: 1 passed, 0 failed, 0 skipped, 1 total
Duration: 0.326`943`583 sec