[NFC] Add libcxx python reformat SHA to .git-blame-ignore-revs
[llvm-project.git] / third-party / benchmark / test / args_product_test.cc
blobd44f391f748006b3daf36026bc0bf506072facbd
1 #include <cassert>
2 #include <iostream>
3 #include <set>
4 #include <vector>
6 #include "benchmark/benchmark.h"
8 class ArgsProductFixture : public ::benchmark::Fixture {
9 public:
10 ArgsProductFixture()
11 : expectedValues({{0, 100, 2000, 30000},
12 {1, 15, 3, 8},
13 {1, 15, 3, 9},
14 {1, 15, 7, 8},
15 {1, 15, 7, 9},
16 {1, 15, 10, 8},
17 {1, 15, 10, 9},
18 {2, 15, 3, 8},
19 {2, 15, 3, 9},
20 {2, 15, 7, 8},
21 {2, 15, 7, 9},
22 {2, 15, 10, 8},
23 {2, 15, 10, 9},
24 {4, 5, 6, 11}}) {}
26 void SetUp(const ::benchmark::State& state) BENCHMARK_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
36 // complete.
37 virtual ~ArgsProductFixture() {
38 if (actualValues != expectedValues) {
39 std::cout << "EXPECTED\n";
40 for (const auto& v : expectedValues) {
41 std::cout << "{";
42 for (int64_t iv : v) {
43 std::cout << iv << ", ";
45 std::cout << "}\n";
47 std::cout << "ACTUAL\n";
48 for (const auto& v : actualValues) {
49 std::cout << "{";
50 for (int64_t iv : v) {
51 std::cout << iv << ", ";
53 std::cout << "}\n";
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) {
64 int64_t product =
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});
77 BENCHMARK_MAIN();