google / benchmark

A microbenchmark support library
Apache License 2.0
8.59k stars 1.57k forks source link

[FR] Reuse benchmark functions with arbitrary fixture templates #1767

Open PhilipDeegan opened 3 months ago

PhilipDeegan commented 3 months ago

Is your feature request related to a problem? Please describe.

Currently, looking at the docs, it does not appear like we can resuse benchmark functions per fixture template, which I find somewhat strange.

Describe the solution you'd like

something like this

template<typename T>
class MyFixture : public benchmark::Fixture {};

BENCHMARK_TEMPLATE_F(MyFixture, Test)(benchmark::State& st) {
   for (auto _ : st) {
     ...
  }
}

BENCHMARK_REGISTER_F(MyFixture, Test, double);
BENCHMARK_REGISTER_F(MyFixture, Test, int);

Describe alternatives you've considered the current function per template type is an alternative, but seems redundant.

Additional context n/a