Skip to content

Commit 169bebd

Browse files
committed
benchmark
1 parent 249cb01 commit 169bebd

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

benchmarks/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,5 +141,6 @@ add_benchmark(unique src/unique.cpp)
141141
add_benchmark(vector_bool_copy src/vector_bool_copy.cpp)
142142
add_benchmark(vector_bool_copy_n src/vector_bool_copy_n.cpp)
143143
add_benchmark(vector_bool_count src/vector_bool_count.cpp)
144+
add_benchmark(vector_bool_meow_of src/vector_bool_meow_of.cpp)
144145
add_benchmark(vector_bool_move src/vector_bool_move.cpp)
145146
add_benchmark(vector_bool_transform src/vector_bool_transform.cpp)
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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 <functional>
9+
#include <vector>
10+
11+
#include "skewed_allocator.hpp"
12+
13+
using namespace std;
14+
15+
enum class alg { any_, all_, none_ };
16+
enum class content { ones_then_zeros, zeros_then_ones };
17+
18+
template <alg Alg, content Content, class Pred = identity>
19+
void meow_of(benchmark::State& state) {
20+
const auto size = static_cast<size_t>(state.range(0));
21+
vector<bool, not_highly_aligned_allocator<bool>> source(size);
22+
23+
if constexpr (Content == content::ones_then_zeros) {
24+
fill(source.begin(), source.begin() + source.size() / 2, true);
25+
} else {
26+
fill(source.begin() + source.size() / 2, source.end(), true);
27+
}
28+
29+
for (auto _ : state) {
30+
benchmark::DoNotOptimize(source);
31+
bool result;
32+
if constexpr (Alg == alg::any_) {
33+
result = any_of(source.begin(), source.end(), Pred{});
34+
} else if constexpr (Alg == alg::all_) {
35+
result = all_of(source.begin(), source.end(), Pred{});
36+
} else {
37+
result = none_of(source.begin(), source.end(), Pred{});
38+
}
39+
benchmark::DoNotOptimize(result);
40+
}
41+
}
42+
43+
void common_args(auto bm) {
44+
bm->RangeMultiplier(64)->Range(64, 64 << 10);
45+
}
46+
47+
using not_ = logical_not<>;
48+
49+
BENCHMARK(meow_of<alg::any_, content::zeros_then_ones>)->Apply(common_args);
50+
BENCHMARK(meow_of<alg::any_, content::ones_then_zeros, not_>)->Apply(common_args);
51+
BENCHMARK(meow_of<alg::all_, content::ones_then_zeros>)->Apply(common_args);
52+
BENCHMARK(meow_of<alg::none_, content::zeros_then_ones>)->Apply(common_args);
53+
54+
BENCHMARK_MAIN();

0 commit comments

Comments
 (0)