[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,86 @@
+//===----------------------------------------------------------------------===//
+//
+// 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"
+#include "test_macros.h"
+
+int main(int argc, char** argv) {
+ auto std_move = [](auto first, auto last, auto out) { return std::move(first, last, out); };
+
+ // {std,ranges}::move(normal container)
+ {
+ auto bm = []<class Container>(std::string name, auto move) {
+ benchmark::RegisterBenchmark(name, [move](auto& st) {
+ std::size_t const size = st.range(0);
+ using ValueType = typename Container::value_type;
+ Container c1(size), c2(size);
+ std::generate_n(c1.begin(), size, [] { return Generate<ValueType>::random(); });
+
+ Container* in = &c1;
+ Container* out = &c2;
+ for ([[maybe_unused]] auto _ : st) {
+ benchmark::DoNotOptimize(in);
+ benchmark::DoNotOptimize(out);
+ auto result = move(in->begin(), in->end(), out->begin());
+ benchmark::DoNotOptimize(result);
+ std::swap(in, out);
+ }
+ })->Range(8, 1 << 20);
+ };
+ bm.operator()<std::vector<int>>("std::move(vector<int>)", std_move);
----------------
philnik777 wrote:
For the copy family of algorithms I think it would be interesting to test some non-trivial type. Specifically, that the compiler would not be able to see through the operation. That could be achieved by an out-of-line definition or a `[[gnu::noinline]]` on the function. Maybe just an optimization barrier would work to.
https://github.com/llvm/llvm-project/pull/127354
More information about the libcxx-commits
mailing list