[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_fill = [](auto first, auto last, auto const& value) { return std::fill(first, last, value); };
+
+  // {std,ranges}::fill(normal container)
+  {
+    auto bm = []<class Container>(std::string name, auto fill) {
+      benchmark::RegisterBenchmark(
+          name,
+          [fill](auto& st) {
+            std::size_t const size = st.range(0);
+            using ValueType        = typename Container::value_type;
+            ValueType x            = Generate<ValueType>::random();
+            ValueType y            = Generate<ValueType>::random();
+            Container c(size, y);
+
+            for ([[maybe_unused]] auto _ : st) {
+              benchmark::DoNotOptimize(c);
+              benchmark::DoNotOptimize(x);
+              fill(c.begin(), c.end(), x);
+              benchmark::DoNotOptimize(c);
+              std::swap(x, y);
----------------
philnik777 wrote:

I don't think there is much value in having two different fill values here. The compiler already has to fill the range again, since we have the `DoNotOptimize` calls around. Same for the `vector<bool>` version and `fill_n`.

https://github.com/llvm/llvm-project/pull/127354


More information about the libcxx-commits mailing list