1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include <algorithm>
10#include <benchmark/benchmark.h>
11#include <vector>
12
13static void bm_equal_iter(benchmark::State& state) {
14 std::vector<char> vec1(state.range(), '1');
15 std::vector<char> vec2(state.range(), '1');
16 for (auto _ : state) {
17 benchmark::DoNotOptimize(vec1);
18 benchmark::DoNotOptimize(vec2);
19 benchmark::DoNotOptimize(std::equal(vec1.begin(), vec1.end(), vec2.begin()));
20 }
21}
22BENCHMARK(bm_equal_iter)->DenseRange(1, 8)->Range(16, 1 << 20);
23
24static void bm_equal(benchmark::State& state) {
25 std::vector<char> vec1(state.range(), '1');
26 std::vector<char> vec2(state.range(), '1');
27 for (auto _ : state) {
28 benchmark::DoNotOptimize(vec1);
29 benchmark::DoNotOptimize(vec2);
30 benchmark::DoNotOptimize(std::equal(vec1.begin(), vec1.end(), vec2.begin(), vec2.end()));
31 }
32}
33BENCHMARK(bm_equal)->DenseRange(1, 8)->Range(16, 1 << 20);
34
35static void bm_ranges_equal(benchmark::State& state) {
36 std::vector<char> vec1(state.range(), '1');
37 std::vector<char> vec2(state.range(), '1');
38 for (auto _ : state) {
39 benchmark::DoNotOptimize(vec1);
40 benchmark::DoNotOptimize(vec2);
41 benchmark::DoNotOptimize(std::ranges::equal(vec1, vec2));
42 }
43}
44BENCHMARK(bm_ranges_equal)->DenseRange(1, 8)->Range(16, 1 << 20);
45
46BENCHMARK_MAIN();
47