[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,78 @@
+//===----------------------------------------------------------------------===//
+//
+// 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++17
+
+// UNSUPPORTED: libcpp-has-no-incomplete-pstl
+
+#include <algorithm>
+#include <cstddef>
+#include <cstdint>
+#include <cmath>
+#include <numeric>
+#include <string>
+#include <type_traits>
+#include <vector>
+#include <execution>
+#include <utility>
+
+#include <benchmark/benchmark.h>
+
+int main(int argc, char** argv) {
+  // A transformation/reduction that does just a bit more than a no-op
+  struct minimal {
+    double operator()(double x) const { return -x; }
+    double operator()(double x, double y) const { return x + y; }
+  };
+
+  // A transformation/reduction that does miniscule work per element
+  struct cheap {
+    double operator()(double x) const { return -x + 0.25; }
+    double operator()(double x, double y) const { return x / 2. * 2. / 2. * 2. + y / 2. * 2. / 2. * 2.; }
+  };
+
+  // A transformation/reduction that does significant work per element
+  struct expensive {
+    double operator()(double x) const { return (-x + 0.25) * (x + 10.); }
+    double operator()(double x, double y) const {
+      return x / 2. * 2. / 3. * 3. / 4. * 4. / 5. * 5. + y / 2. * 2. / 2. * 2. / 4. * 4. / 5. * 5.;
----------------
ldionne wrote:

Let's add a short comment explaining that compilers are not allowed to optimize this without fast-math.

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


More information about the libcxx-commits mailing list