mirror of https://github.com/google/benchmark.git
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: Jen-yee Hong <pcmantw@google.com>
This commit is contained in:
parent
5b7518482c
commit
c932169e76
17
README.md
17
README.md
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue