[libcxx-commits] [libcxx] [libc++][pstl] Add more benchmarks of the parallel algorithms (PR #225908)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Sep 24 08:49:06 PDT 2026
================
@@ -0,0 +1,72 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: std-at-least-c++20
+
+// UNSUPPORTED: libcpp-has-no-incomplete-pstl
+
+#include <algorithm>
+#include <cstddef>
+#include <cstdint>
+#include <string>
+#include <vector>
+#include <execution>
+#include <utility>
+
+#include <benchmark/benchmark.h>
+
+#include "common.h"
+#include "test_macros.h"
+
+int main(int argc, char** argv) {
+ auto bm = [](std::string name, auto&& policy, auto generate_data) {
+ benchmark::RegisterBenchmark(
+ name,
+ [&policy, generate_data](auto& st) mutable {
+ std::size_t size = st.range(0);
+ std::vector<int> data = generate_data(size);
+ std::vector<int> c = data;
+
+ for ([[maybe_unused]] auto _ : st) {
+ benchmark::DoNotOptimize(c);
+ std::sort(policy, c.begin(), c.end());
+ benchmark::DoNotOptimize(c);
+
+ // Reset c to its original unsorted state
+ st.PauseTiming();
----------------
ldionne wrote:
`st.PauseTiming();` is really expensive -- we've been investigating serial benchmarks where we ended up only measuring the cost of `PauseTiming()` / `ResumeTiming()`.
At 64 elements, it's not clear to me that we're measuring anything meaningful as-is. I would recommend either using the batched approach we use in the serial benchmarks, or dropping the 64 size from here. If we drop 64, we should also add a comment explaining that we assume `PauseTiming` isn't dominating the benchmark.
https://github.com/llvm/llvm-project/pull/225908
More information about the libcxx-commits
mailing list