[libcxx-commits] [libcxx] [libc++] Add remaining benchmarks from [alg.modifying.operations] (PR #127354)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Feb 24 13:22:35 PST 2025
================
@@ -0,0 +1,71 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 <iterator>
+#include <list>
+#include <string>
+#include <vector>
+
+#include "benchmark/benchmark.h"
+#include "../../GenerateInput.h"
+
+int main(int argc, char** argv) {
+ auto std_transform = [](auto first1, auto last1, auto first2, auto, auto out, auto f) {
+ return std::transform(first1, last1, first2, out, f);
+ };
+
+ // {std,ranges}::transform(normal container, normal container)
+ {
+ auto bm = []<class Container>(std::string name, auto transform) {
+ benchmark::RegisterBenchmark(
+ name,
+ [transform](auto& st) {
+ std::size_t const size = st.range(0);
+ using ValueType = typename Container::value_type;
+ Container c1, c2;
+ std::generate_n(std::back_inserter(c1), size, [] { return Generate<ValueType>::random(); });
+ std::generate_n(std::back_inserter(c2), size, [] { return Generate<ValueType>::random(); });
+
+ std::vector<ValueType> out(size);
+
+ auto f = [](auto& x, auto& y) {
+ benchmark::DoNotOptimize(x);
+ benchmark::DoNotOptimize(y);
+ return x + y;
+ };
+
+ for ([[maybe_unused]] auto _ : st) {
+ benchmark::DoNotOptimize(c1);
+ benchmark::DoNotOptimize(c2);
+ benchmark::DoNotOptimize(out);
+ auto result = transform(c1.begin(), c1.end(), c2.begin(), c2.end(), out.begin(), f);
+ benchmark::DoNotOptimize(result);
+ }
+ })
+ ->Arg(32)
+ ->Arg(1024)
+ ->Arg(8192);
+ };
+ bm.operator()<std::vector<int>>("std::transform(vector<int>, vector<int>)", std_transform);
----------------
philnik777 wrote:
I think we should also add benchmarks for cases where the output is a segmented iterator (i.e. output to a deque) for the `_copy` versions of algorithms.
https://github.com/llvm/llvm-project/pull/127354
More information about the libcxx-commits
mailing list