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

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

template <typename TFunctor>
void operator()(TFunctor&& a_functor)

Class: fcf::NTest::Duration

Package: fcfTest

File: test.hpp

Available from version: 1.0.1

Executes a callable object multiple times and measures the total execution time

The fcf::NTest::Duration call operator provides an automated way to perform benchmarking. When invoked, it executes the provided functor (lambda, function pointer, or function object) for the exact number of iterations specified during the Duration object's construction.

The method internally handles the timing lifecycle: it calls begin() before the loop and end() after all iterations are completed.

Arguments

TFunctor&& a_functor
- functor called to perform the measured operation. TFunctor - The type of the callable object to be measured.

Example: Benchmarking a Lambda

The most common usage for measuring small, inline code blocks.

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

Example: Benchmarking an Existing Function

Passing a function pointer to the duration object.

void heavy_workload() { // Simulate work std::this_thread::sleep_for(std::chrono::microseconds(10)); } fcf::NTest::Duration bench(50); bench(heavy_workload); fcf::NTest::log() << "Total time: " << bench.totalDuration().count() << " ns" << std::endl;