A common need when designing experiments like ours is to check it on different sizes of arguments. Such needs can be addressed in Google Benchmark in a number of ways. The simplest is to just add a call to Args() on the object returned by the BENCHMARK macros. This way, we can pass a single set of values to use in a given microbenchmark. To use the passed value, we'd need to change our benchmark function as follows:
void search_in_sorted_vector(benchmark::State &state, auto finder) {
const auto haystack = make_sorted_vector<int>(state.range(0));
const auto needle = 2137;
for (auto _ : state) {
benchmark::DoNotOptimize(finder(haystack, needle));
}
}
The call to state.range(0) will read the 0-th argument passed. An arbitrary number can be supported. In our case, it's used to parameterize the haystack size. What if we wanted to pass a range of value sets instead? This way, we could see how changing the size influences...