Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / benchmarks / algorithms / equal.bench.cpp
blob6d63d8c48ce1e06da43e924f4c98958dbb8c191c
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 //===----------------------------------------------------------------------===//
9 #include <algorithm>
10 #include <benchmark/benchmark.h>
11 #include <vector>
13 static 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()));
22 BENCHMARK(bm_equal_iter)->DenseRange(1, 8)->Range(16, 1 << 20);
24 static 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()));
33 BENCHMARK(bm_equal)->DenseRange(1, 8)->Range(16, 1 << 20);
35 static 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));
44 BENCHMARK(bm_ranges_equal)->DenseRange(1, 8)->Range(16, 1 << 20);
46 BENCHMARK_MAIN();