[libcxx-commits] [libcxx] [libc++] Add benchmarks for partitioning algorithms (PR #127324)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Tue Feb 25 06:34:16 PST 2025


================
@@ -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
+//
+//===----------------------------------------------------------------------===//
+
+// 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"
+
+auto compute_median(auto first, auto last) {
+  std::vector v(first, last);
+  auto middle = v.begin() + v.size() / 2;
+  std::nth_element(v.begin(), middle, v.end());
+  return *middle;
+}
+
+int main(int argc, char** argv) {
+  auto std_partition = [](auto first, auto last, auto pred) { return std::partition(first, last, pred); };
+
+  auto bm = []<class Container>(std::string name, auto partition) {
----------------
ldionne wrote:

I just implemented this test case and verified that we performed fewer moves (the sparse case did approx. 6x fewer moves than the dense case), yet the timings are basically the same. I will still provide both benchmarks, but the TLDR is that it doesn't seem to matter much with our current implementation.

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


More information about the libcxx-commits mailing list