[libcxx-commits] [libcxx] [libc++] Refactor std::push_heap benchmark (PR #181343)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Feb 13 07:07:02 PST 2026
================
@@ -0,0 +1,90 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 <array>
+#include <cstddef>
+#include <deque>
+#include <string>
+#include <vector>
+
+#include "benchmark/benchmark.h"
+#include "common.h"
+
+int main(int argc, char** argv) {
+ // Benchmark {std,ranges}::sort on various types of data
+ //
+ // We perform this benchmark in a batch because we need to restore the
+ // state of the container after the operation.
+ {
+ auto bm = []<class Container>(std::string name, auto pred, auto generate_data) {
+ benchmark::RegisterBenchmark(
+ name,
+ [pred, generate_data](auto& st) {
+ std::size_t const size = st.range(0);
+ constexpr std::size_t BatchSize = 32;
+ using ValueType = typename Container::value_type;
+ std::vector<ValueType> data = generate_data(size);
+ std::array<Container, BatchSize> c;
+ std::fill_n(c.begin(), BatchSize, Container(data.begin(), data.end()));
+
+ while (st.KeepRunningBatch(BatchSize * size)) {
+ for (std::size_t i = 0; i != BatchSize; ++i) {
+ benchmark::DoNotOptimize(c[i]);
+ for (size_t k = 0; k != c[i].size(); ++k)
+ std::push_heap(c[i].begin(), c[i].begin() + k);
+ std::make_heap(c[i].begin(), c[i].end(), pred);
+ std::sort_heap(c[i].begin(), c[i].end(), pred);
----------------
ldionne wrote:
Why do you make heap and sort heap here?
https://github.com/llvm/llvm-project/pull/181343
More information about the libcxx-commits
mailing list