[libcxx-commits] [libcxx] [libc++] Fix the batch sized used in the std::gcd benchmark (PR #120618)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Thu Dec 19 10:26:42 PST 2024


https://github.com/ldionne created https://github.com/llvm/llvm-project/pull/120618

Since that benchmark is testing n*n inputs, the batch size reported to GoogleBenchmark should be that amount. Otherwise, GoogleBenchmark reports the timing for calling std::gcd on the whole sequence, which is misleading.

>From 6113cf12d10e08d8df15a424f96b7032d1300be8 Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Thu, 19 Dec 2024 13:24:55 -0500
Subject: [PATCH] [libc++] Fix the batch sized used in the std::gcd benchmark

Since that benchmark is testing n*n inputs, the batch size reported
to GoogleBenchmark should be that amount. Otherwise, GoogleBenchmark
reports the timing for calling std::gcd on the whole sequence, which
is misleading.
---
 libcxx/test/benchmarks/numeric/gcd.bench.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/test/benchmarks/numeric/gcd.bench.cpp b/libcxx/test/benchmarks/numeric/gcd.bench.cpp
index abbc7e9dd04f96..ca5fed59463a21 100644
--- a/libcxx/test/benchmarks/numeric/gcd.bench.cpp
+++ b/libcxx/test/benchmarks/numeric/gcd.bench.cpp
@@ -25,7 +25,7 @@ static std::array<T, 1000> generate(std::uniform_int_distribution<T> distributio
 
 static void bm_gcd_random(benchmark::State& state) {
   std::array data = generate<int>();
-  while (state.KeepRunningBatch(data.size()))
+  while (state.KeepRunningBatch(data.size() * data.size()))
     for (auto v0 : data)
       for (auto v1 : data)
         benchmark::DoNotOptimize(std::gcd(v0, v1));



More information about the libcxx-commits mailing list