[libcxx-commits] [libcxx] [libc++] Rewrite the std::pop_heap benchmark (PR #179911)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Thu Feb 5 03:18:05 PST 2026


https://github.com/philnik777 created https://github.com/llvm/llvm-project/pull/179911

None

>From 4ceb137170052ac7eab88f6862b8600cf4bf42cc Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Thu, 5 Feb 2026 12:17:30 +0100
Subject: [PATCH] [libc++] Rewrite the std::pop_heap benchmark

---
 .../algorithms/sorting/pop_heap.bench.cpp     | 52 +++++++++++++++++++
 1 file changed, 52 insertions(+)
 create mode 100644 libcxx/test/benchmarks/algorithms/sorting/pop_heap.bench.cpp

diff --git a/libcxx/test/benchmarks/algorithms/sorting/pop_heap.bench.cpp b/libcxx/test/benchmarks/algorithms/sorting/pop_heap.bench.cpp
new file mode 100644
index 0000000000000..ad0ca8bff3a5b
--- /dev/null
+++ b/libcxx/test/benchmarks/algorithms/sorting/pop_heap.bench.cpp
@@ -0,0 +1,52 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 <deque>
+#include <iterator>
+#include <vector>
+
+#include "benchmark/benchmark.h"
+#include "../../GenerateInput.h"
+
+int main(int argc, char** argv) {
+  auto bm = []<class Container>(std::type_identity<Container>, std::string name) {
+    benchmark::RegisterBenchmark(name, [](benchmark::State& state) {
+      std::size_t size = state.range(0);
+
+      Container c;
+      std::generate_n(std::back_inserter(c), size, [] { return Generate<typename Container::value_type>::random(); });
+
+      while (state.KeepRunningBatch(size)) {
+        state.PauseTiming();
+        std::make_heap(c.begin(), c.end());
+        state.ResumeTiming();
+
+        for (auto first = c.begin(), last = c.end(); last != first; --last) {
+          std::pop_heap(first, last);
+        }
+      }
+    })->Arg(8)->Arg(1024)->Arg(8192);
+  };
+
+  bm(std::type_identity<std::vector<int>>{}, "std::pop_heap(vector<int>)");
+  bm(std::type_identity<std::vector<float>>{}, "std::pop_heap(vector<float>)");
+  bm(std::type_identity<std::vector<size_t>>{}, "std::pop_heap(vector<size_t>)");
+  bm(std::type_identity<std::vector<std::string>>{}, "std::pop_heap(vector<std::string>)");
+  bm(std::type_identity<std::deque<int>>{}, "std::pop_heap(deque<int>)");
+  bm(std::type_identity<std::deque<float>>{}, "std::pop_heap(deque<float>)");
+  bm(std::type_identity<std::deque<size_t>>{}, "std::pop_heap(deque<size_t>)");
+  bm(std::type_identity<std::deque<std::string>>{}, "std::pop_heap(deque<std::string>)");
+
+  benchmark::Initialize(&argc, argv);
+  benchmark::RunSpecifiedBenchmarks();
+  benchmark::Shutdown();
+  return 0;
+}



More information about the libcxx-commits mailing list