[libcxx-commits] [libcxx] [libc++] Merge the two swap_ranges benchmarks into one (PR #214712)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Aug 10 00:30:26 PDT 2026
================
@@ -55,6 +58,36 @@ int main(int argc, char** argv) {
bm.operator()<std::list<int>>("std::swap_ranges(list<int>)", std_swap_ranges);
}
+ // {std,ranges}::swap_ranges(vector<bool>)
+ {
+ auto bm = []<bool Aligned>(std::string name, auto swap_ranges) {
+ benchmark::RegisterBenchmark(
+ name,
+ [swap_ranges](auto& st) {
+ std::size_t const size = st.range(0);
+ std::vector<bool> c1(size, true);
+ std::vector<bool> c2(Aligned ? size : size + 8, false);
+ auto first1 = c1.begin();
+ auto last1 = c1.end();
+ auto first2 = Aligned ? c2.begin() : c2.begin() + 4;
+ auto last2 = Aligned ? c2.end() : c2.end() - 4;
+
+ for ([[maybe_unused]] auto _ : st) {
+ benchmark::DoNotOptimize(c1);
+ benchmark::DoNotOptimize(c2);
+ auto result = swap_ranges(first1, last1, first2, last2);
+ benchmark::DoNotOptimize(result);
+ }
+ })
+ ->Arg(50) // non power-of-two
+ ->Range(64, 1 << 20);
+ };
+ bm.operator()<true>("std::swap_ranges(vector<bool>) (aligned)", std_swap_ranges);
+ bm.operator()<false>("std::swap_ranges(vector<bool>) (unaligned)", std_swap_ranges);
+ bm.operator()<true>("rng::swap_ranges(vector<bool>) (aligned)", ranges_swap_ranges);
+ bm.operator()<false>("rng::swap_ranges(vector<bool>) (unaligned)", ranges_swap_ranges);
----------------
philnik777 wrote:
We've dropped the `ranges::` benchmarks elsewhere if they don't provide any additional coverage (which I think is the case here).
https://github.com/llvm/llvm-project/pull/214712
More information about the libcxx-commits
mailing list