[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,137 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 <cassert>
+#include <cstddef>
+#include <deque>
+#include <list>
+#include <string>
+#include <vector>
+
+#include <benchmark/benchmark.h>
+#include "../../GenerateInput.h"
+
+int main(int argc, char** argv) {
+ auto std_search = [](auto first1, auto last1, auto first2, auto last2) {
+ return std::search(first1, last1, first2, last2);
+ };
+ auto std_search_pred = [](auto first1, auto last1, auto first2, auto last2) {
+ return std::search(first1, last1, first2, last2, [](auto& x, auto& y) {
+ benchmark::DoNotOptimize(x);
+ benchmark::DoNotOptimize(y);
+ return x == y;
+ });
+ };
+ auto ranges_search_pred = [](auto first1, auto last1, auto first2, auto last2) {
+ return std::ranges::search(first1, last1, first2, last2, [](auto& x, auto& y) {
+ benchmark::DoNotOptimize(x);
+ benchmark::DoNotOptimize(y);
+ return x == y;
+ });
+ };
+
----------------
philnik777 wrote:
We should also add benchmarks for the cases
- when the two ranges are the same length and are equal
- when the subrange is just a single element
https://github.com/llvm/llvm-project/pull/128206
More information about the libcxx-commits
mailing list