[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:03 PST 2025
================
@@ -0,0 +1,152 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 <numeric>
+#include <string>
+#include <vector>
+
+#include <benchmark/benchmark.h>
+#include "../../GenerateInput.h"
+
+int main(int argc, char** argv) {
+ auto std_any_of = [](auto first, auto last, auto pred) { return std::any_of(first, last, pred); };
+ auto std_all_of = [](auto first, auto last, auto pred) {
+ // match semantics of any_of
+ return !std::all_of(first, last, [pred](auto x) { return !pred(x); });
+ };
+ auto std_none_of = [](auto first, auto last, auto pred) {
+ // match semantics of any_of
+ return !std::none_of(first, last, pred);
+ };
+
+ auto ranges_all_of = [](auto first, auto last, auto pred) {
+ // match semantics of any_of
+ return !std::ranges::all_of(first, last, [pred](auto x) { return !pred(x); });
+ };
+ auto ranges_none_of = [](auto first, auto last, auto pred) {
+ // match semantics of any_of
+ return !std::ranges::none_of(first, last, pred);
+ };
+
+ // Benchmark {std,ranges}::{any_of,all_of,none_of} where we bail out early
+ // (after visiting 25% of the elements).
+ {
+ auto bm = []<class Container>(std::string name, auto any_of) {
----------------
philnik777 wrote:
Does it make sense to bail out at 25%? I'd guess it will just be 4x faster than the whole range. This applies throughout the algorithms.
https://github.com/llvm/llvm-project/pull/128206
More information about the libcxx-commits
mailing list