From bf7e7e2397a3a286a4a0c333a84027363b9d1097 Mon Sep 17 00:00:00 2001 From: Zack Puhl Date: Thu, 14 Aug 2025 14:24:37 -0400 Subject: [PATCH] Fix Benchmark Progress Printing (#2401) --- lib/std/core/runtime_benchmark.c3 | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/std/core/runtime_benchmark.c3 b/lib/std/core/runtime_benchmark.c3 index 277374600..dcf56a73f 100644 --- a/lib/std/core/runtime_benchmark.c3 +++ b/lib/std/core/runtime_benchmark.c3 @@ -110,14 +110,18 @@ fn bool run_benchmarks(BenchmarkUnit[] benchmarks) uint current_benchmark_iterations = bench_fn_iters[unit.name] ?? benchmark_max_iterations; char[] perc_str = { [0..19] = ' ', [20] = 0 }; int perc = 0; + uint print_step = current_benchmark_iterations / 100; for (this_iteration = 0; this_iteration < current_benchmark_iterations; ++this_iteration) { - perc_str[0..(uint)math::floor((this_iteration / (float)current_benchmark_iterations) * 20)] = '#'; - perc = (uint)math::ceil(100 * (this_iteration / (float)current_benchmark_iterations)); + if (0 == this_iteration % print_step) // only print right about when the % will update + { + perc_str[0..(uint)math::floor((this_iteration / (float)current_benchmark_iterations) * 20)] = '#'; + perc = (uint)math::ceil(100 * (this_iteration / (float)current_benchmark_iterations)); - io::printf("\r%s [%s] %d / %d (%d%%)", name.str_view(), (ZString)perc_str, this_iteration, current_benchmark_iterations, perc); - io::stdout().flush()!!; + io::printf("\r%s [%s] %d / %d (%d%%)", name.str_view(), (ZString)perc_str, this_iteration, current_benchmark_iterations, perc); + io::stdout().flush()!!; + } @start_benchmark(); // can be overridden by calls inside the unit's func