Unverified Commit c932169e by PCMan Committed by GitHub

Provide helpers to create integer lists for the given ranges. (#1179)

This can be used together with ArgsProduct() to allow multiple ranges with different multipliers and mixing dense and sparse ranges. Example: BENCHMARK(MyTest)->ArgsProduct({ CreateRange(0, 1024, /*multi=*/32), CreateRange(0, 100, /*multi=*/4), CreateDenseRange(0, 4, /*step=*/1) }); Co-authored-by: 's avatarJen-yee Hong <pcmantw@google.com>
parent 5b751848
......@@ -616,6 +616,23 @@ BENCHMARK(BM_SetInsert)
->Args({8<<10, 80});
```
For the most common scenarios, helper methods for creating a list of
integers for a given sparse or dense range are provided.
```c++
BENCHMARK(BM_SetInsert)
->ArgsProduct({
benchmark::CreateRange(8, 128, /*multi=*/2),
benchmark::CreateDenseRange(1, 4, /*step=*/1)
})
// would generate the same benchmark arguments as
BENCHMARK(BM_SetInsert)
->ArgsProduct({
{8, 16, 32, 64, 128},
{1, 2, 3, 4}
});
```
For more complex patterns of inputs, passing a custom function to `Apply` allows
programmatic specification of an arbitrary set of arguments on which to run the
benchmark. The following example enumerates a dense range on one parameter,
......
......@@ -1649,6 +1649,21 @@ inline double GetTimeUnitMultiplier(TimeUnit unit) {
BENCHMARK_UNREACHABLE();
}
// Creates a list of integer values for the given range and multiplier.
// This can be used together with ArgsProduct() to allow multiple ranges
// with different multiplers.
// Example:
// ArgsProduct({
// CreateRange(0, 1024, /*multi=*/32),
// CreateRange(0, 100, /*multi=*/4),
// CreateDenseRange(0, 4, /*step=*/1),
// });
std::vector<int64_t> CreateRange(int64_t lo, int64_t hi, int multi);
// Creates a list of integer values for the given range and step.
std::vector<int64_t> CreateDenseRange(int64_t start, int64_t limit,
int step);
} // namespace benchmark
#endif // BENCHMARK_BENCHMARK_H_
......@@ -458,4 +458,20 @@ void ClearRegisteredBenchmarks() {
internal::BenchmarkFamilies::GetInstance()->ClearBenchmarks();
}
std::vector<int64_t> CreateRange(int64_t lo, int64_t hi, int multi) {
std::vector<int64_t> args;
internal::AddRange(&args, lo, hi, multi);
return args;
}
std::vector<int64_t> CreateDenseRange(int64_t start, int64_t limit,
int step) {
CHECK_LE(start, limit);
std::vector<int64_t> args;
for (int64_t arg = start; arg <= limit; arg += step) {
args.push_back(arg);
}
return args;
}
} // end namespace benchmark
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment