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 <cstring> |
12 | #include <random> |
13 | #include <vector> |
14 | |
15 | static void bm_vector_bool_count(benchmark::State& state) { |
16 | std::vector<bool> vec1(state.range(), false); |
17 | |
18 | for (auto _ : state) { |
19 | benchmark::DoNotOptimize(value&: vec1); |
20 | benchmark::DoNotOptimize(value: std::count(first: vec1.begin(), last: vec1.end(), value: true)); |
21 | } |
22 | } |
23 | BENCHMARK(bm_vector_bool_count)->DenseRange(start: 1, limit: 8)->Range(start: 16, limit: 1 << 20); |
24 | |
25 | static void bm_vector_bool_ranges_count(benchmark::State& state) { |
26 | std::vector<bool> vec1(state.range(), false); |
27 | |
28 | for (auto _ : state) { |
29 | benchmark::DoNotOptimize(value&: vec1); |
30 | benchmark::DoNotOptimize(std::ranges::count(vec1.begin(), vec1.end(), true)); |
31 | } |
32 | } |
33 | BENCHMARK(bm_vector_bool_ranges_count)->DenseRange(start: 1, limit: 8)->Range(start: 16, limit: 1 << 20); |
34 | |
35 | BENCHMARK_MAIN(); |
36 | |