2016-08-04 19:30:14 +00:00
|
|
|
#include "benchmark/benchmark.h"
|
|
|
|
|
|
|
|
#include <cassert>
|
2016-10-07 18:04:50 +00:00
|
|
|
#include <set>
|
2016-08-04 19:30:14 +00:00
|
|
|
|
|
|
|
class MultipleRangesFixture : public ::benchmark::Fixture {
|
|
|
|
public:
|
2016-08-07 20:57:39 +00:00
|
|
|
MultipleRangesFixture()
|
2016-10-07 18:04:50 +00:00
|
|
|
: expectedValues({{1, 3, 5},
|
|
|
|
{1, 3, 8},
|
|
|
|
{1, 3, 15},
|
|
|
|
{2, 3, 5},
|
|
|
|
{2, 3, 8},
|
|
|
|
{2, 3, 15},
|
|
|
|
{1, 4, 5},
|
|
|
|
{1, 4, 8},
|
|
|
|
{1, 4, 15},
|
|
|
|
{2, 4, 5},
|
|
|
|
{2, 4, 8},
|
|
|
|
{2, 4, 15},
|
|
|
|
{1, 7, 5},
|
|
|
|
{1, 7, 8},
|
|
|
|
{1, 7, 15},
|
|
|
|
{2, 7, 5},
|
|
|
|
{2, 7, 8},
|
|
|
|
{2, 7, 15},
|
|
|
|
{7, 6, 3}}) {}
|
2016-08-04 19:30:14 +00:00
|
|
|
|
|
|
|
void SetUp(const ::benchmark::State& state) {
|
|
|
|
std::vector<int> ranges = {state.range(0), state.range(1), state.range(2)};
|
|
|
|
|
|
|
|
assert(expectedValues.find(ranges) != expectedValues.end());
|
|
|
|
|
|
|
|
actualValues.insert(ranges);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~MultipleRangesFixture() {
|
|
|
|
assert(actualValues.size() == expectedValues.size());
|
|
|
|
}
|
2016-10-07 18:04:50 +00:00
|
|
|
|
2016-08-04 19:30:14 +00:00
|
|
|
std::set<std::vector<int>> expectedValues;
|
|
|
|
std::set<std::vector<int>> actualValues;
|
|
|
|
};
|
|
|
|
|
|
|
|
BENCHMARK_DEFINE_F(MultipleRangesFixture, Empty)(benchmark::State& state) {
|
2017-10-17 18:17:02 +00:00
|
|
|
for (auto _ : state) {
|
2016-08-04 19:30:14 +00:00
|
|
|
int product = state.range(0) * state.range(1) * state.range(2);
|
|
|
|
for (int x = 0; x < product; x++) {
|
|
|
|
benchmark::DoNotOptimize(x);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-07 18:04:50 +00:00
|
|
|
BENCHMARK_REGISTER_F(MultipleRangesFixture, Empty)
|
|
|
|
->RangeMultiplier(2)
|
|
|
|
->Ranges({{1, 2}, {3, 7}, {5, 15}})
|
|
|
|
->Args({7, 6, 3});
|
2016-08-29 17:59:46 +00:00
|
|
|
|
|
|
|
void BM_CheckDefaultArgument(benchmark::State& state) {
|
|
|
|
// Test that the 'range()' without an argument is the same as 'range(0)'.
|
|
|
|
assert(state.range() == state.range(0));
|
|
|
|
assert(state.range() != state.range(1));
|
2017-10-17 18:17:02 +00:00
|
|
|
for (auto _ : state) {
|
2016-10-07 18:04:50 +00:00
|
|
|
}
|
2016-08-29 17:59:46 +00:00
|
|
|
}
|
|
|
|
BENCHMARK(BM_CheckDefaultArgument)->Ranges({{1, 5}, {6, 10}});
|
2016-08-04 19:30:14 +00:00
|
|
|
|
2016-08-29 05:07:38 +00:00
|
|
|
static void BM_MultipleRanges(benchmark::State& st) {
|
2017-10-17 18:17:02 +00:00
|
|
|
for (auto _ : st) {
|
2016-10-07 18:04:50 +00:00
|
|
|
}
|
2016-08-29 05:07:38 +00:00
|
|
|
}
|
|
|
|
BENCHMARK(BM_MultipleRanges)->Ranges({{5, 5}, {6, 6}});
|
|
|
|
|
2017-12-04 01:45:07 +00:00
|
|
|
BENCHMARK_MAIN();
|