[libcxx-commits] [libcxx] [libc++] Fix calling push_heap on an empty range in the push_heap benchmark (PR #227076)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Tue Sep 29 06:06:40 PDT 2026


================
@@ -39,7 +39,7 @@ int main(int argc, char** argv) {
             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)
+                for (size_t k = 1; k <= c[i].size(); ++k)
----------------
ldionne wrote:

We do `c[i].begin() + 1` until `c[i].begin() + c[i].size()` -- the second one corresponds to the one-past-the-end iterator for `c[i]`. If we stopped at `k == c[i].size() - 1` (which would be the case if we did `k != <...>`), then we'd never be passing the full range to the algorithm.

All in all it doesn't matter too much since this is a benchmark and our goal is only to measure how long it takes, but IIUC the current form is correct.

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


More information about the libcxx-commits mailing list