18 #include "benchmark/benchmark.h" 24 constexpr
int kMinBenchmarkSize = 1024;
25 constexpr
int kMaxBenchmarkSize = 8 * 1024 * 1024;
34 explicit EightBits(
int ) :
data(0) {}
35 bool operator==(
const EightBits& rhs)
const {
return data == rhs.data; }
40 void BM_absl_equal_benchmark(benchmark::State& state) {
41 std::vector<T> xs(state.range(0), T(0));
42 std::vector<T> ys = xs;
43 while (state.KeepRunning()) {
44 const bool same =
absl::equal(xs.begin(), xs.end(), ys.begin(), ys.end());
45 benchmark::DoNotOptimize(same);
50 void BM_std_equal_benchmark(benchmark::State& state) {
51 std::vector<T> xs(state.range(0), T(0));
52 std::vector<T> ys = xs;
53 while (state.KeepRunning()) {
54 const bool same = std::equal(xs.begin(), xs.end(), ys.begin());
55 benchmark::DoNotOptimize(same);
60 void BM_memcmp_benchmark(benchmark::State& state) {
61 std::vector<T> xs(state.range(0), T(0));
62 std::vector<T> ys = xs;
63 while (state.KeepRunning()) {
65 std::memcmp(xs.data(), ys.data(), xs.size() *
sizeof(T)) == 0;
66 benchmark::DoNotOptimize(same);
73 void BM_absl_equal_self_benchmark(benchmark::State& state) {
74 std::vector<T> xs(state.range(0), T(0));
75 while (state.KeepRunning()) {
76 const bool same =
absl::equal(xs.begin(), xs.end(), xs.begin(), xs.end());
77 benchmark::DoNotOptimize(same);
81 BENCHMARK_TEMPLATE(BM_absl_equal_benchmark, uint8_t)
82 ->Range(kMinBenchmarkSize, kMaxBenchmarkSize);
83 BENCHMARK_TEMPLATE(BM_std_equal_benchmark, uint8_t)
84 ->Range(kMinBenchmarkSize, kMaxBenchmarkSize);
85 BENCHMARK_TEMPLATE(BM_memcmp_benchmark, uint8_t)
86 ->Range(kMinBenchmarkSize, kMaxBenchmarkSize);
87 BENCHMARK_TEMPLATE(BM_absl_equal_self_benchmark, uint8_t)
88 ->Range(kMinBenchmarkSize, kMaxBenchmarkSize);
90 BENCHMARK_TEMPLATE(BM_absl_equal_benchmark, uint16_t)
91 ->Range(kMinBenchmarkSize, kMaxBenchmarkSize);
92 BENCHMARK_TEMPLATE(BM_std_equal_benchmark, uint16_t)
93 ->Range(kMinBenchmarkSize, kMaxBenchmarkSize);
94 BENCHMARK_TEMPLATE(BM_memcmp_benchmark, uint16_t)
95 ->Range(kMinBenchmarkSize, kMaxBenchmarkSize);
96 BENCHMARK_TEMPLATE(BM_absl_equal_self_benchmark, uint16_t)
97 ->Range(kMinBenchmarkSize, kMaxBenchmarkSize);
99 BENCHMARK_TEMPLATE(BM_absl_equal_benchmark, uint32_t)
100 ->Range(kMinBenchmarkSize, kMaxBenchmarkSize);
101 BENCHMARK_TEMPLATE(BM_std_equal_benchmark, uint32_t)
102 ->Range(kMinBenchmarkSize, kMaxBenchmarkSize);
103 BENCHMARK_TEMPLATE(BM_memcmp_benchmark, uint32_t)
104 ->Range(kMinBenchmarkSize, kMaxBenchmarkSize);
105 BENCHMARK_TEMPLATE(BM_absl_equal_self_benchmark, uint32_t)
106 ->Range(kMinBenchmarkSize, kMaxBenchmarkSize);
108 BENCHMARK_TEMPLATE(BM_absl_equal_benchmark, uint64_t)
109 ->Range(kMinBenchmarkSize, kMaxBenchmarkSize);
110 BENCHMARK_TEMPLATE(BM_std_equal_benchmark, uint64_t)
111 ->Range(kMinBenchmarkSize, kMaxBenchmarkSize);
112 BENCHMARK_TEMPLATE(BM_memcmp_benchmark, uint64_t)
113 ->Range(kMinBenchmarkSize, kMaxBenchmarkSize);
114 BENCHMARK_TEMPLATE(BM_absl_equal_self_benchmark, uint64_t)
115 ->Range(kMinBenchmarkSize, kMaxBenchmarkSize);
117 BENCHMARK_TEMPLATE(BM_absl_equal_benchmark, EightBits)
118 ->Range(kMinBenchmarkSize, kMaxBenchmarkSize);
119 BENCHMARK_TEMPLATE(BM_std_equal_benchmark, EightBits)
120 ->Range(kMinBenchmarkSize, kMaxBenchmarkSize);
121 BENCHMARK_TEMPLATE(BM_memcmp_benchmark, EightBits)
122 ->Range(kMinBenchmarkSize, kMaxBenchmarkSize);
123 BENCHMARK_TEMPLATE(BM_absl_equal_self_benchmark, EightBits)
124 ->Range(kMinBenchmarkSize, kMaxBenchmarkSize);
bool operator==(const absl::InlinedVector< T, N, A > &a, const absl::InlinedVector< T, N, A > &b)
static char data[kDataSize]
bool equal(InputIter1 first1, InputIter1 last1, InputIter2 first2, InputIter2 last2, Pred &&pred)