[libcxx-commits] [libcxx] [libc++] Refactor and add benchmarks from [alg.nonmodifying] (PR #128206)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Mon Feb 24 14:44:02 PST 2025


================
@@ -0,0 +1,82 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+#include <algorithm>
+#include <cstddef>
+#include <deque>
+#include <iterator>
+#include <list>
+#include <vector>
+
+#include <benchmark/benchmark.h>
+
+int main(int argc, char** argv) {
+  // Benchmark ranges::contains_subrange where we find our target starting at 25% of the elements
+  {
+    auto bm = []<class Container>(std::string name) {
+      benchmark::RegisterBenchmark(
+          name,
+          [](auto& st) {
+            std::size_t const size = st.range(0);
+            Container c(size, 1);
----------------
philnik777 wrote:

```suggestion
            Container c(size, 1);
```
The `1` should be a `Container::value_type` instead to make it trivial to add benchmarks for different types.

https://github.com/llvm/llvm-project/pull/128206


More information about the libcxx-commits mailing list