operator()() method from fcf::NTest::DurationBasic class
Class:
Package: fcfTest
File: test.hpp
Available from version: 1.2.5
Executes a function and measures its duration.
The
This method is highly overloaded to support various measurement configurations.
Arguments
- Configuration options for the measurement.
- Starting level for recording.
- Ending level for recording.
- The callable object to be benchmarked.
Example: Benchmarking a Lambda
The simplest way to benchmark a piece of code using a lambda expression.
#define FCF_TEST_IMPLEMENTATION
#include <fcfTest/test.hpp>
#include <vector>
#include <algorithm>
FCF_TEST_DEFINE ("Bench", "Lambda", "SortTest") {
fcf::NTest::Duration bench(1000);
bench ([](){
std::vector <int > v = {5, 2, 9, 1, 5, 6};
std::sort (v.begin(), v.end());
});
fcf::NTest::log () << "Benchmark completed." << std::endl;
fcf::NTest::log () << " Duration: " << bench.duration ().str (true) << std::endl;
fcf::NTest::log () << " Average: " << bench.average ().str (true) << 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" -> "Lambda" -> "SortTest" ...
> Benchmark completed.
> Duration: 0.000`707`227
> Average: 0.000`000`707
[SUCCESS] Test completed successfully (0.000`737`940 sec)
[SUCCESS] All tests were completed.
Tests: 1 passed, 0 failed, 0 skipped, 1 total
Duration: 0.000`737`940 sec
VPSDime is an industry leading VPS hosting company that provides virtualized server services with high performance, availability and friendly support.