[libcxx-commits] [libcxx] [libc++] Drop the unrepresentative search_n benchmark (PR #184783)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Thu Mar 5 04:40:28 PST 2026


https://github.com/philnik777 created https://github.com/llvm/llvm-project/pull/184783

This benchmark isn't very good at benchmarking `search_n`, since a good `search_n` implementation can go through it in ~10 perfectly predictable steps. We can drop it to avoid spening unnecessary resources. This also fixes that the two benchmark sets have identical names.


>From dfedf3af22201965989c2e373b8f8d5f2140a6b9 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Thu, 5 Mar 2026 13:37:02 +0100
Subject: [PATCH] [libc++] Drop the unrepresentative search_n benchmark

---
 .../nonmodifying/search_n.bench.cpp           | 36 -------------------
 1 file changed, 36 deletions(-)

diff --git a/libcxx/test/benchmarks/algorithms/nonmodifying/search_n.bench.cpp b/libcxx/test/benchmarks/algorithms/nonmodifying/search_n.bench.cpp
index f25d10f3d652d..212aabfd7cdb3 100644
--- a/libcxx/test/benchmarks/algorithms/nonmodifying/search_n.bench.cpp
+++ b/libcxx/test/benchmarks/algorithms/nonmodifying/search_n.bench.cpp
@@ -31,42 +31,6 @@ int main(int argc, char** argv) {
     });
   };
 
-  // Benchmark {std,ranges}::search_n where the needle is never found (worst case).
-  {
-    auto bm = []<class Container>(std::string name, auto search_n) {
-      benchmark::RegisterBenchmark(
-          name,
-          [search_n](auto& st) {
-            std::size_t const size = st.range(0);
-            using ValueType        = typename Container::value_type;
-            ValueType x            = Generate<ValueType>::random();
-            ValueType y            = random_different_from({x});
-            Container haystack(size, x);
-            std::size_t n = size / 10; // needle size is 10% of the haystack
-
-            for ([[maybe_unused]] auto _ : st) {
-              benchmark::DoNotOptimize(haystack);
-              benchmark::DoNotOptimize(n);
-              benchmark::DoNotOptimize(y);
-              auto result = search_n(haystack.begin(), haystack.end(), n, y);
-              benchmark::DoNotOptimize(result);
-            }
-          })
-          ->Arg(32)
-          ->Arg(1024)
-          ->Arg(8192);
-    };
-    // {std,ranges}::search_n
-    bm.operator()<std::vector<int>>("std::search_n(vector<int>) (no match)", std_search_n);
-    bm.operator()<std::deque<int>>("std::search_n(deque<int>) (no match)", std_search_n);
-    bm.operator()<std::list<int>>("std::search_n(list<int>) (no match)", std_search_n);
-
-    // {std,ranges}::search_n(pred)
-    bm.operator()<std::vector<int>>("std::search_n(vector<int>, pred) (no match)", std_search_n_pred);
-    bm.operator()<std::deque<int>>("std::search_n(deque<int>, pred) (no match)", std_search_n_pred);
-    bm.operator()<std::list<int>>("std::search_n(list<int>, pred) (no match)", std_search_n_pred);
-  }
-
   // Benchmark {std,ranges}::search_n where the needle almost matches a lot.
   {
     auto bm = []<class Container>(std::string name, auto search_n) {



More information about the libcxx-commits mailing list