6 #include "benchmark/benchmark.h"
8 class ArgsProductFixture
: public ::benchmark::Fixture
{
11 : expectedValues({{0, 100, 2000, 30000},
26 void SetUp(const ::benchmark::State
& state
) override
{
27 std::vector
<int64_t> ranges
= {state
.range(0), state
.range(1),
28 state
.range(2), state
.range(3)};
30 assert(expectedValues
.find(ranges
) != expectedValues
.end());
32 actualValues
.insert(ranges
);
35 // NOTE: This is not TearDown as we want to check after _all_ runs are
37 ~ArgsProductFixture() override
{
38 if (actualValues
!= expectedValues
) {
39 std::cout
<< "EXPECTED\n";
40 for (const auto& v
: expectedValues
) {
42 for (int64_t iv
: v
) {
43 std::cout
<< iv
<< ", ";
47 std::cout
<< "ACTUAL\n";
48 for (const auto& v
: actualValues
) {
50 for (int64_t iv
: v
) {
51 std::cout
<< iv
<< ", ";
58 std::set
<std::vector
<int64_t>> expectedValues
;
59 std::set
<std::vector
<int64_t>> actualValues
;
62 BENCHMARK_DEFINE_F(ArgsProductFixture
, Empty
)(benchmark::State
& state
) {
63 for (auto _
: state
) {
65 state
.range(0) * state
.range(1) * state
.range(2) * state
.range(3);
66 for (int64_t x
= 0; x
< product
; x
++) {
67 benchmark::DoNotOptimize(x
);
72 BENCHMARK_REGISTER_F(ArgsProductFixture
, Empty
)
73 ->Args({0, 100, 2000, 30000})
74 ->ArgsProduct({{1, 2}, {15}, {3, 7, 10}, {8, 9}})
75 ->Args({4, 5, 6, 11});