File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed
Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -135,4 +135,5 @@ add_benchmark(swap_ranges src/swap_ranges.cpp)
135135add_benchmark(unique src/unique.cpp)
136136add_benchmark(vector_bool_copy src/vector_bool_copy.cpp)
137137add_benchmark(vector_bool_copy_n src/vector_bool_copy_n.cpp)
138+ add_benchmark(vector_bool_count src/vector_bool_count.cpp)
138139add_benchmark(vector_bool_move src/vector_bool_move.cpp)
Original file line number Diff line number Diff line change 1+ // Copyright (c) Microsoft Corporation.
2+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+ #include < benchmark/benchmark.h>
5+ //
6+ #include < algorithm>
7+ #include < cstddef>
8+ #include < random>
9+ #include < vector>
10+
11+ using namespace std ;
12+
13+ vector<bool > createRandomVector (const size_t size) {
14+ mt19937 gen;
15+ bernoulli_distribution dist{0.5 };
16+ vector<bool > result (size);
17+ generate (result.begin (), result.end (), [&] { return dist (gen); });
18+ return result;
19+ }
20+
21+ void count_aligned (benchmark::State& state) {
22+ const auto size = static_cast <size_t >(state.range (0 ));
23+ vector<bool > v = createRandomVector (size);
24+
25+ bool b = false ;
26+
27+ for (auto _ : state) {
28+ benchmark::DoNotOptimize (b);
29+ benchmark::DoNotOptimize (v);
30+ auto r = count (v.cbegin (), v.cend (), b);
31+ benchmark::DoNotOptimize (r);
32+ b = !b;
33+ }
34+ }
35+
36+
37+ BENCHMARK (count_aligned)->RangeMultiplier(64 )->Range(64 , 64 << 10 );
38+
39+ BENCHMARK_MAIN ();
You can’t perform that action at this time.
0 commit comments