Hacking the whole BENCHMARK_MAIN
function is of course one way to do it, but IMO it's really cumbersome and really ugly. So I'm just gonna propose a different approach:
// define your chunksize and iteration count combinations here (for i and j)
static void CustomArguments(benchmark::internal::Benchmark* b) {
for (int i = 0; i <= 10; ++i)
for (int j = 0; j <= 50; ++j)
b->Args({i, j});
}
// the string (name of the used function is passed later)
static void TestBenchmark(benchmark::State& state, std::string func_name) {
// cout for testing purposes
std::cout << state.range(0) /* = i */ << " " << state.range(1) /* = j */
<< " " << func_name << std::endl;
for (auto _ : state) {
// do whatever with i and j and func_name
}
}
// This macro is used to pass the string "function_name1/2/3"
// as a parameter to TestBenchmark
BENCHMARK_CAPTURE(TestBenchmark, benchmark_name1, "function_name1")
->Apply(CustomArguments);
BENCHMARK_CAPTURE(TestBenchmark, benchmark_name2, "function_name2")
->Apply(CustomArguments);
BENCHMARK_CAPTURE(TestBenchmark, benchmark_name3, "function_name3")
->Apply(CustomArguments);
BENCHMARK_MAIN()
And then in your go script, you call the benchmark with a regex filter:
./prog_name --benchmark_filter=InsertRegexFilterHere
So for example:
./prog_name --benchmark_filter=TestBenchmark/benchmark_name2/5/35
The above example will call the benchmark and will pass "function_name2", 5 and 35 (these are the values for your chunksize and iteration count) and so the output will be something like:
------------------------------------------------------------------------------
Benchmark Time CPU Iterations
------------------------------------------------------------------------------
TestBenchmark/benchmark_name2/5/35 2 ns 2 ns 308047644
./prog_name --benchmark_format=json
. – Pretoriabenchmark::RegisterBenchmark
via->Arg(...)
, rather than using a global variable. – Zannini