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

duration() method from fcf::NTest::Duration class

std::chrono::nanoseconds duration()

Class: fcf::NTest::Duration

Package: fcfTest

File: test.hpp

Available from version: 1.0.1

Returns the average duration of a single iteration in nanoseconds

The duration() method calculates the average time taken by a single execution cycle. It is computed by dividing the total elapsed time (between begin() and end()) by the number of iterations configured in the fcf::NTest::Duration object

Result
std::chrono::nanoseconds
- The average duration expressed in nanoseconds

Example: Automated Benchmarking

When using the call operator, the average duration is automatically calculated after all iterations are completed

fcf::NTest::Duration bench(1000); bench([]() { // Task to measure int x = 0; for(int i = 0; i < 100; ++i) x += i; }); fcf::NTest::log() << "Average time: " << bench.duration().count() << " ns" << std::endl;

Example: Manual Timing

Useful when wrapping a manual loop to obtain the mean execution time per iteration

fcf::NTest::Duration bench(500); bench.begin(); for(unsigned long long i = 0; i < bench.iterations(); ++i) { // Workload } bench.end(); fcf::NTest::log() << "Average: " << bench.duration().count() << " ns" << std::endl;