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

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

fcf::NTest::TimeDuration average(int a_level = 0) const

Class: fcf::NTest::DurationBasic

Package: fcfTest

File: test.hpp

Available from version: 1.2.5

Returns the average duration for a specific level.

The average method calculates the mean duration of all iterations performed at the specified measurement level.

Arguments

int a_level = 0
- The index of the measurement level.
Result
fcf::NTest::TimeDuration
- The average duration recorded for the specified level.

Example: Calculating Average Duration

Demonstrating how to get the average time per iteration.

#define FCF_TEST_IMPLEMENTATION #include <fcfTest/test.hpp> #include <thread> #include <chrono> FCF_TEST_DEFINE("Bench", "Stats", "AverageTest") { fcf::NTest::Duration bench(100 /*a_iterationCount*/, 1 /*a_measurementStep*/, 0 /*a_warmupCount*/); bench.begin(0); std::this_thread::sleep_for(std::chrono::seconds(1)); bench.end(0); fcf::NTest::TimeDuration avg = bench.average(0); fcf::NTest::log() << "Average duration: " << avg << 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" -> "Duration" -> "GetDuration" ... > Total duration: 1.000125905 [SUCCESS] Test completed successfully (1.000`194`347 sec) [SUCCESS] All tests were completed. Tests: 1 passed, 0 failed, 0 skipped, 1 total Duration: 1.000`194`347 sec