Skip to content

Commit 2162665

Browse files
committed
Re-add benchmark for std::equal with vector<bool>
1 parent b21656a commit 2162665

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

libcxx/test/benchmarks/algorithms/nonmodifying/equal.bench.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,42 @@ int main(int argc, char** argv) {
100100
bm.operator()<std::list<int>>("rng::equal(list<int>) (it, it, it, it, pred)", ranges_equal_4leg_pred);
101101
}
102102

103+
// Benchmark {std,ranges}::equal on vector<bool>.
104+
{
105+
auto bm = [](std::string name, auto equal, bool aligned) {
106+
benchmark::RegisterBenchmark(
107+
name,
108+
[=](auto& st) {
109+
std::size_t const size = st.range();
110+
std::vector<bool> c1(size, true);
111+
std::vector<bool> c2(size + 8, true);
112+
auto first1 = c1.begin();
113+
auto last1 = c1.end();
114+
auto first2 = aligned ? c2.begin() : c2.begin() + 4;
115+
auto last2 = aligned ? c2.end() : c2.end() - 4;
116+
for (auto _ : st) {
117+
benchmark::DoNotOptimize(c1);
118+
benchmark::DoNotOptimize(c2);
119+
auto result = equal(first1, last1, first2, last2);
120+
benchmark::DoNotOptimize(result);
121+
}
122+
})
123+
->Arg(8)
124+
->Arg(50) // non power-of-two
125+
->Arg(1024)
126+
->Arg(8192)
127+
->Arg(1 << 20);
128+
};
129+
130+
// {std,ranges}::equal(vector<bool>) (aligned)
131+
bm("std::equal(vector<bool>) (aligned)", std_equal_4leg, true);
132+
bm("rng::equal(vector<bool>) (aligned)", std::ranges::equal, true);
133+
134+
// {std,ranges}::equal(vector<bool>) (unaligned)
135+
bm("std::equal(vector<bool>) (unaligned)", std_equal_4leg, false);
136+
bm("rng::equal(vector<bool>) (unaligned)", std::ranges::equal, false);
137+
}
138+
103139
benchmark::Initialize(&argc, argv);
104140
benchmark::RunSpecifiedBenchmarks();
105141
benchmark::Shutdown();

0 commit comments

Comments
 (0)