2016-08-05 03:30:14 +08:00
|
|
|
#include <cassert>
|
2018-04-04 06:12:47 +08:00
|
|
|
#include <iostream>
|
2016-10-08 02:04:50 +08:00
|
|
|
#include <set>
|
2018-04-04 06:12:47 +08:00
|
|
|
#include <vector>
|
2016-08-05 03:30:14 +08:00
|
|
|
|
2021-11-11 00:22:31 +08:00
|
|
|
#include "benchmark/benchmark.h"
|
|
|
|
|
2016-08-05 03:30:14 +08:00
|
|
|
class MultipleRangesFixture : public ::benchmark::Fixture {
|
|
|
|
public:
|
2016-08-08 04:57:39 +08:00
|
|
|
MultipleRangesFixture()
|
2016-10-08 02:04:50 +08: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-05 03:30:14 +08:00
|
|
|
|
2023-01-10 01:52:18 +08:00
|
|
|
void SetUp(const ::benchmark::State& state) override {
|
2018-04-04 06:12:47 +08:00
|
|
|
std::vector<int64_t> ranges = {state.range(0), state.range(1),
|
|
|
|
state.range(2)};
|
2016-08-05 03:30:14 +08:00
|
|
|
|
|
|
|
assert(expectedValues.find(ranges) != expectedValues.end());
|
|
|
|
|
|
|
|
actualValues.insert(ranges);
|
|
|
|
}
|
|
|
|
|
2018-04-04 06:12:47 +08:00
|
|
|
// NOTE: This is not TearDown as we want to check after _all_ runs are
|
|
|
|
// complete.
|
2023-01-10 01:52:18 +08:00
|
|
|
~MultipleRangesFixture() override {
|
2019-03-26 18:50:53 +08:00
|
|
|
if (actualValues != expectedValues) {
|
2018-04-04 06:12:47 +08:00
|
|
|
std::cout << "EXPECTED\n";
|
2021-12-06 19:18:04 +08:00
|
|
|
for (const auto& v : expectedValues) {
|
2018-04-04 06:12:47 +08:00
|
|
|
std::cout << "{";
|
|
|
|
for (int64_t iv : v) {
|
|
|
|
std::cout << iv << ", ";
|
|
|
|
}
|
|
|
|
std::cout << "}\n";
|
|
|
|
}
|
|
|
|
std::cout << "ACTUAL\n";
|
2021-12-06 19:18:04 +08:00
|
|
|
for (const auto& v : actualValues) {
|
2018-04-04 06:12:47 +08:00
|
|
|
std::cout << "{";
|
|
|
|
for (int64_t iv : v) {
|
|
|
|
std::cout << iv << ", ";
|
|
|
|
}
|
|
|
|
std::cout << "}\n";
|
|
|
|
}
|
|
|
|
}
|
2016-08-05 03:30:14 +08:00
|
|
|
}
|
2016-10-08 02:04:50 +08:00
|
|
|
|
2018-04-04 06:12:47 +08:00
|
|
|
std::set<std::vector<int64_t>> expectedValues;
|
|
|
|
std::set<std::vector<int64_t>> actualValues;
|
2016-08-05 03:30:14 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
BENCHMARK_DEFINE_F(MultipleRangesFixture, Empty)(benchmark::State& state) {
|
2017-10-18 02:17:02 +08:00
|
|
|
for (auto _ : state) {
|
2018-04-04 06:12:47 +08:00
|
|
|
int64_t product = state.range(0) * state.range(1) * state.range(2);
|
|
|
|
for (int64_t x = 0; x < product; x++) {
|
2016-08-05 03:30:14 +08:00
|
|
|
benchmark::DoNotOptimize(x);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-08 02:04:50 +08:00
|
|
|
BENCHMARK_REGISTER_F(MultipleRangesFixture, Empty)
|
|
|
|
->RangeMultiplier(2)
|
|
|
|
->Ranges({{1, 2}, {3, 7}, {5, 15}})
|
|
|
|
->Args({7, 6, 3});
|
2016-08-30 01:59:46 +08: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-18 02:17:02 +08:00
|
|
|
for (auto _ : state) {
|
2016-10-08 02:04:50 +08:00
|
|
|
}
|
2016-08-30 01:59:46 +08:00
|
|
|
}
|
|
|
|
BENCHMARK(BM_CheckDefaultArgument)->Ranges({{1, 5}, {6, 10}});
|
2016-08-05 03:30:14 +08:00
|
|
|
|
2016-08-29 13:07:38 +08:00
|
|
|
static void BM_MultipleRanges(benchmark::State& st) {
|
2017-10-18 02:17:02 +08:00
|
|
|
for (auto _ : st) {
|
2016-10-08 02:04:50 +08:00
|
|
|
}
|
2016-08-29 13:07:38 +08:00
|
|
|
}
|
|
|
|
BENCHMARK(BM_MultipleRanges)->Ranges({{5, 5}, {6, 6}});
|
|
|
|
|
2017-12-04 09:45:07 +08:00
|
|
|
BENCHMARK_MAIN();
|