Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / benchmarks / algorithms / count.bench.cpp
blob7370293fd6efd0c38002c2446821112fc4d417e0
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 <cstring>
12 #include <random>
13 #include <vector>
15 static void bm_vector_bool_count(benchmark::State& state) {
16 std::vector<bool> vec1(state.range(), false);
18 for (auto _ : state) {
19 benchmark::DoNotOptimize(vec1);
20 benchmark::DoNotOptimize(std::count(vec1.begin(), vec1.end(), true));
23 BENCHMARK(bm_vector_bool_count)->DenseRange(1, 8)->Range(16, 1 << 20);
25 static void bm_vector_bool_ranges_count(benchmark::State& state) {
26 std::vector<bool> vec1(state.range(), false);
28 for (auto _ : state) {
29 benchmark::DoNotOptimize(vec1);
30 benchmark::DoNotOptimize(std::ranges::count(vec1.begin(), vec1.end(), true));
33 BENCHMARK(bm_vector_bool_ranges_count)->DenseRange(1, 8)->Range(16, 1 << 20);
35 BENCHMARK_MAIN();