6 #include "benchmark/benchmark.h"
8 class MultipleRangesFixture
: public ::benchmark::Fixture
{
10 MultipleRangesFixture()
11 : expectedValues({{1, 3, 5},
31 void SetUp(const ::benchmark::State
& state
) BENCHMARK_OVERRIDE
{
32 std::vector
<int64_t> ranges
= {state
.range(0), state
.range(1),
35 assert(expectedValues
.find(ranges
) != expectedValues
.end());
37 actualValues
.insert(ranges
);
40 // NOTE: This is not TearDown as we want to check after _all_ runs are
42 virtual ~MultipleRangesFixture() {
43 if (actualValues
!= expectedValues
) {
44 std::cout
<< "EXPECTED\n";
45 for (const auto& v
: expectedValues
) {
47 for (int64_t iv
: v
) {
48 std::cout
<< iv
<< ", ";
52 std::cout
<< "ACTUAL\n";
53 for (const auto& v
: actualValues
) {
55 for (int64_t iv
: v
) {
56 std::cout
<< iv
<< ", ";
63 std::set
<std::vector
<int64_t>> expectedValues
;
64 std::set
<std::vector
<int64_t>> actualValues
;
67 BENCHMARK_DEFINE_F(MultipleRangesFixture
, Empty
)(benchmark::State
& state
) {
68 for (auto _
: state
) {
69 int64_t product
= state
.range(0) * state
.range(1) * state
.range(2);
70 for (int64_t x
= 0; x
< product
; x
++) {
71 benchmark::DoNotOptimize(x
);
76 BENCHMARK_REGISTER_F(MultipleRangesFixture
, Empty
)
78 ->Ranges({{1, 2}, {3, 7}, {5, 15}})
81 void BM_CheckDefaultArgument(benchmark::State
& state
) {
82 // Test that the 'range()' without an argument is the same as 'range(0)'.
83 assert(state
.range() == state
.range(0));
84 assert(state
.range() != state
.range(1));
85 for (auto _
: state
) {
88 BENCHMARK(BM_CheckDefaultArgument
)->Ranges({{1, 5}, {6, 10}});
90 static void BM_MultipleRanges(benchmark::State
& st
) {
94 BENCHMARK(BM_MultipleRanges
)->Ranges({{5, 5}, {6, 6}});