Skip to content

Commit 3bc4100

Browse files
committed
Fix stats printing for floats and negative deltas
Ratio in YJIT might print something like this: #8: 1918ms 0.305937303071417 #9: 1950ms -0.396978503607869
1 parent f92f4a7 commit 3bc4100

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

harness/harness-common.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def return_results(warmup_iterations, bench_iterations)
114114
if yjit_stats
115115
yjit_bench_results["yjit_stats"] = yjit_stats
116116

117-
formatted_stats = proc { |key| "%10s" % yjit_stats[key].to_s.reverse.scan(/\d{1,3}/).join(",").reverse }
117+
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(".") }
118118
yjit_stats_keys = [
119119
*ENV.fetch("YJIT_BENCH_STATS", "").split(",").map(&:to_sym),
120120
:inline_code_size,

harness/harness.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,16 @@ def run_benchmark(_num_itrs_hint, &block)
5959

6060
yjit_stats&.each do |key, old_value|
6161
new_value = RubyVM::YJIT.runtime_stats(key)
62-
diff = (new_value - old_value).to_s.reverse.scan(/\d{1,3}/).join(",").reverse
62+
63+
# Insert comma separators but only in the whole number portion.
64+
diff = (new_value - old_value).to_s.split(".").tap do |a|
65+
# Preserve any leading minus sign that may be on the beginning.
66+
a[0] = a[0].reverse.scan(/\d{1,3}-?/).join(",").reverse
67+
# Add a space when positive so that if there is ever a negative
68+
# the first digit will line up.
69+
a[0].prepend(" ") unless a[0].start_with?("-")
70+
end.join(".")
71+
6372
itr_str << " %#{key.size}s" % diff
6473
yjit_stats[key] = new_value
6574
end

0 commit comments

Comments
 (0)