Skip to content

Commit 35773de

Browse files
authored
Fix stats printing for floats and negative deltas (#357)
* Fix stats printing for floats and negative deltas Ratio in YJIT might print something like this: #8: 1918ms 0.305937303071417 #9: 1950ms -0.396978503607869 * Move number formatting to a method
1 parent f92f4a7 commit 35773de

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

harness/harness-common.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@
1313
# Seed the global random number generator for repeatability between runs
1414
Random.srand(1337)
1515

16+
def format_number(num)
17+
num.to_s.split(".").tap do |a|
18+
# Insert comma separators but only in the whole number portion (a[0]).
19+
# Look for "-?" at the end to preserve any leading minus sign that may be on the beginning.
20+
a[0] = a[0].reverse.scan(/\d{1,3}-?/).join(",").reverse
21+
22+
# Add a space when positive so that if there is ever a negative
23+
# the first digit will line up.
24+
a[0].prepend(" ") unless a[0].start_with?("-")
25+
end.join(".")
26+
end
27+
1628
def run_cmd(*args)
1729
puts "Command: #{args.join(" ")}"
1830
system(*args)
@@ -114,7 +126,7 @@ def return_results(warmup_iterations, bench_iterations)
114126
if yjit_stats
115127
yjit_bench_results["yjit_stats"] = yjit_stats
116128

117-
formatted_stats = proc { |key| "%10s" % yjit_stats[key].to_s.reverse.scan(/\d{1,3}/).join(",").reverse }
129+
formatted_stats = proc { |key| "%10s" % format_number(yjit_stats[key]) }
118130
yjit_stats_keys = [
119131
*ENV.fetch("YJIT_BENCH_STATS", "").split(",").map(&:to_sym),
120132
:inline_code_size,

harness/harness.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ 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
63-
itr_str << " %#{key.size}s" % diff
62+
diff = (new_value - old_value)
63+
itr_str << " %#{key.size}s" % format_number(diff)
6464
yjit_stats[key] = new_value
6565
end
6666

0 commit comments

Comments
 (0)