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

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

std::chrono::nanoseconds totalDuration()

Class: fcf::NTest::Duration

Package: fcfTest

File: test.hpp

Available from version: 1.0.1

Returns the total elapsed time of all benchmark iterations in nanoseconds

The totalDuration() method calculates the cumulative time elapsed between the begin() and end() calls, covering all executed iterations. It is used to retrieve the absolute measurement of the entire benchmarking session.

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

Example: Automated Benchmarking

When using the call operator, the total 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() << "Total time: " << bench.totalDuration().count() << " ns" << std::endl;

Example: Manual Benchmarking

Useful when wrapping a loop manually to get the total time spent in the block

fcf::NTest::Duration bench(100); bench.begin(); for(int i = 0; i < bench.iterations(); ++i) { // Task to measure int x = 0; for(int i = 0; i < 100; ++i) x += i; } bench.end(); fcf::NTest::log() << "Total time: " << bench.totalDuration().count() << " ns" << std::endl;