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(value&: vec1);
18 benchmark::DoNotOptimize(value&: vec2);
19 benchmark::DoNotOptimize(value: std::equal(first1: vec1.begin(), last1: vec1.end(), first2: vec2.begin()));
20 }
21}
22BENCHMARK(bm_equal_iter)->DenseRange(start: 1, limit: 8)->Range(start: 16, limit: 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(value&: vec1);
29 benchmark::DoNotOptimize(value&: vec2);
30 benchmark::DoNotOptimize(value: std::equal(first1: vec1.begin(), last1: vec1.end(), first2: vec2.begin(), last2: vec2.end()));
31 }
32}
33BENCHMARK(bm_equal)->DenseRange(start: 1, limit: 8)->Range(start: 16, limit: 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(value&: vec1);
40 benchmark::DoNotOptimize(value&: vec2);
41 benchmark::DoNotOptimize(std::ranges::equal(vec1, vec2));
42 }
43}
44BENCHMARK(bm_ranges_equal)->DenseRange(start: 1, limit: 8)->Range(start: 16, limit: 1 << 20);
45
46BENCHMARK_MAIN();
47

source code of libcxx/benchmarks/algorithms/equal.bench.cpp