[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:04 PST 2025


================
@@ -0,0 +1,134 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+
+#include <algorithm>
+#include <cstddef>
+#include <deque>
+#include <list>
+#include <string>
+#include <vector>
+
+#include <benchmark/benchmark.h>
+#include "../../GenerateInput.h"
+
+int main(int argc, char** argv) {
+  auto ranges_find_last_if = [](auto first, auto last, auto const& value) {
+    return std::ranges::find_last_if(first, last, [&](auto element) {
+      benchmark::DoNotOptimize(element);
+      return element == value;
+    });
+  };
+  auto ranges_find_last_if_not = [](auto first, auto last, auto const& value) {
+    return std::ranges::find_last_if_not(first, last, [&](auto element) {
+      benchmark::DoNotOptimize(element);
+      return element != value;
+    });
+  };
+
+  // Benchmark ranges::{find_last,find_last_if,find_last_if_not} where the last element
+  // is found 25% into the sequence
----------------
philnik777 wrote:

Can we go for 10% and 90% instead just to make it symmetrical?

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


More information about the libcxx-commits mailing list