From 3bc4100901b78311992530971176f835eac87cc6 Mon Sep 17 00:00:00 2001 From: Randy Stauner Date: Tue, 21 Jan 2025 16:14:48 -0700 Subject: [PATCH 1/2] Fix stats printing for floats and negative deltas Ratio in YJIT might print something like this: #8: 1918ms 0.305937303071417 #9: 1950ms -0.396978503607869 --- harness/harness-common.rb | 2 +- harness/harness.rb | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/harness/harness-common.rb b/harness/harness-common.rb index dfab8a14..4d059bae 100644 --- a/harness/harness-common.rb +++ b/harness/harness-common.rb @@ -114,7 +114,7 @@ def return_results(warmup_iterations, bench_iterations) if yjit_stats yjit_bench_results["yjit_stats"] = yjit_stats - formatted_stats = proc { |key| "%10s" % yjit_stats[key].to_s.reverse.scan(/\d{1,3}/).join(",").reverse } + formatted_stats = proc { |key| "%10s" % yjit_stats[key].to_s.split(".").tap { |a| a[0] = a[0].reverse.scan(/\d{1,3}/).join(",").reverse }.join(".") } yjit_stats_keys = [ *ENV.fetch("YJIT_BENCH_STATS", "").split(",").map(&:to_sym), :inline_code_size, diff --git a/harness/harness.rb b/harness/harness.rb index c32254d5..a9711ad7 100644 --- a/harness/harness.rb +++ b/harness/harness.rb @@ -59,7 +59,16 @@ def run_benchmark(_num_itrs_hint, &block) yjit_stats&.each do |key, old_value| new_value = RubyVM::YJIT.runtime_stats(key) - diff = (new_value - old_value).to_s.reverse.scan(/\d{1,3}/).join(",").reverse + + # Insert comma separators but only in the whole number portion. + diff = (new_value - old_value).to_s.split(".").tap do |a| + # Preserve any leading minus sign that may be on the beginning. + a[0] = a[0].reverse.scan(/\d{1,3}-?/).join(",").reverse + # Add a space when positive so that if there is ever a negative + # the first digit will line up. + a[0].prepend(" ") unless a[0].start_with?("-") + end.join(".") + itr_str << " %#{key.size}s" % diff yjit_stats[key] = new_value end From 1f41835098d4ae2100660dc928e99698188c2081 Mon Sep 17 00:00:00 2001 From: Randy Stauner Date: Wed, 22 Jan 2025 08:45:17 -0700 Subject: [PATCH 2/2] Move number formatting to a method --- harness/harness-common.rb | 14 +++++++++++++- harness/harness.rb | 13 ++----------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/harness/harness-common.rb b/harness/harness-common.rb index 4d059bae..a2b54e69 100644 --- a/harness/harness-common.rb +++ b/harness/harness-common.rb @@ -13,6 +13,18 @@ # Seed the global random number generator for repeatability between runs Random.srand(1337) +def format_number(num) + num.to_s.split(".").tap do |a| + # Insert comma separators but only in the whole number portion (a[0]). + # Look for "-?" at the end to preserve any leading minus sign that may be on the beginning. + a[0] = a[0].reverse.scan(/\d{1,3}-?/).join(",").reverse + + # Add a space when positive so that if there is ever a negative + # the first digit will line up. + a[0].prepend(" ") unless a[0].start_with?("-") + end.join(".") +end + def run_cmd(*args) puts "Command: #{args.join(" ")}" system(*args) @@ -114,7 +126,7 @@ def return_results(warmup_iterations, bench_iterations) if yjit_stats yjit_bench_results["yjit_stats"] = yjit_stats - formatted_stats = proc { |key| "%10s" % yjit_stats[key].to_s.split(".").tap { |a| a[0] = a[0].reverse.scan(/\d{1,3}/).join(",").reverse }.join(".") } + formatted_stats = proc { |key| "%10s" % format_number(yjit_stats[key]) } yjit_stats_keys = [ *ENV.fetch("YJIT_BENCH_STATS", "").split(",").map(&:to_sym), :inline_code_size, diff --git a/harness/harness.rb b/harness/harness.rb index a9711ad7..f1dd8405 100644 --- a/harness/harness.rb +++ b/harness/harness.rb @@ -59,17 +59,8 @@ def run_benchmark(_num_itrs_hint, &block) yjit_stats&.each do |key, old_value| new_value = RubyVM::YJIT.runtime_stats(key) - - # Insert comma separators but only in the whole number portion. - diff = (new_value - old_value).to_s.split(".").tap do |a| - # Preserve any leading minus sign that may be on the beginning. - a[0] = a[0].reverse.scan(/\d{1,3}-?/).join(",").reverse - # Add a space when positive so that if there is ever a negative - # the first digit will line up. - a[0].prepend(" ") unless a[0].start_with?("-") - end.join(".") - - itr_str << " %#{key.size}s" % diff + diff = (new_value - old_value) + itr_str << " %#{key.size}s" % format_number(diff) yjit_stats[key] = new_value end