[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,58 @@
+//===----------------------------------------------------------------------===//
+//
+// 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_shift_left = [](auto first, auto last, auto n) { return std::shift_left(first, last, n); };
+
+ // std::shift_left(normal container)
+ {
+ auto bm = []<class Container>(std::string name, auto shift_left) {
+ benchmark::RegisterBenchmark(
+ name,
+ [shift_left](auto& st) {
+ std::size_t const size = st.range(0);
+ using ValueType = typename Container::value_type;
+ Container c;
+ std::generate_n(std::back_inserter(c), size, [] { return Generate<ValueType>::random(); });
+
+ auto const n = 9 * (size / 10); // shift all but 10% of the range
+
+ for ([[maybe_unused]] auto _ : st) {
+ benchmark::DoNotOptimize(c);
+ auto result = shift_left(c.begin(), c.end(), n);
----------------
philnik777 wrote:
I think it doesn't make a ton of sense to just shift the same range again and again, since everything will be moved-from at some point. This isn't a problem right now, but it will be if we ever benchmark with non-trivially movable types.
https://github.com/llvm/llvm-project/pull/127354
More information about the libcxx-commits
mailing list