Example of a benchmark with a custom output with statistics.
#include <random>
[[nodiscard]] double approx_pi(int num_points);
public:
ApproxPiFixture() {
->add(100)
->add(1000)
->add(10000);
}
};
const int num_points =
constexpr double expected = 3.14159265358979323846;
auto error_output =
thread_index, sample_index, ) {
const double approx = approx_pi(num_points);
const double error = std::abs(approx - expected);
error_output->add(thread_index, sample_index, error);
};
}
double approx_pi(int num_points) {
std::mt19937_64 engine(std::random_device{}());
std::uniform_real_distribution<double> dist(-1.0, 1.0);
int num_inside = 0;
for (int i = 0; i < num_points; ++i) {
const double x = dist(engine);
const double y = dist(engine);
if (x * x + y * y <= 1.0) {
++num_inside;
}
}
return 4.0 * static_cast<double>(num_inside) /
static_cast<double>(num_points);
}
Definition of macros for benchmarks.
#define STAT_BENCH_MAIN
Macro of default main function.
#define STAT_BENCH_MEASURE_INDEXED( THREAD_INDEX_VAR, SAMPLE_INDEX_VAR, ITERATION_INDEX_VAR)
Macro to measure a function.
#define STAT_BENCH_CASE_F(FIXTURE_NAME, GROUP_NAME, CASE_NAME)
Macro to define a case using a fixture.
auto add_param(const param::ParameterName ¶m_name) -> std::shared_ptr< param::ParameterValueVector< T > >
Add a parameter.
Definition of current_invocation_context function.
auto current_invocation_context() -> InvocationContext &
Get the current invocation context.