benchmark_runner Class Reference

A class to run multiple suites of benchmarks. More...

#include <atria/testing/benchmark.hpp>

Public Member Functions

 benchmark_runner (int argc, char const *const *argv, benchmark_settings settings={})
 
template<typename InitFnT >
auto suite (std::string name, InitFnT &&init_fn) -> benchmark_suite< estd::decay_t< InitFnT > >
 
auto suite (std::string name) -> benchmark_suite<>
 

Detailed Description

A class to run multiple suites of benchmarks.

The runs can be configured by passing the command line arguments and default settings to the constructor.

The suite method can be used to create benchmark suites. If an init function is passed, benchmarks are passed data constructed with it. Otherwise they should expect no arguments. Benchmark functions should return a value that depends on the computation under test, to prevent the functions to be optimized away by the compiler. An example is worth a thousand words:

void benchmarks(benchmark_runner runner)
{
// Compare summing values with different methods. Example of
// benchmarks without initialization data.
runner.suite("summing values")
("operator+", [] { return 1 + 2; })
("std::plus", [] { return std::plus<int>{}(1, 2); })
;
// Compare summing vectors with different methods. The time it
// takes to prepare the input data is not counted. Note how the
// init function takes the configured data size into account, so
// the user can try different runs with different input sizes.
runner.suite("summing vectors", [](benchmark_settings conf) {
auto data = std::vector<int>(conf.size);
std::itoa(data.begin(), data.end(), 1);
return data;
})
("std::accumulate", [] (const std::vector<int>& data) {
return std::accumulate(data.begin(), data.end(), std::plus<int>{});
})
("range for loop", [] (const std::vector<int>& data) {
int total;
for (auto n : data) total += n;
return total;
})
;
}

Definition at line 256 of file benchmark.hpp.


The documentation for this class was generated from the following file:
Fork me on GitHub