Skip to content

Commit

Permalink
Fix stats printing for floats and negative deltas
Browse files Browse the repository at this point in the history
Ratio in YJIT might print something like this:
 #8: 1918ms  0.305937303071417
 #9: 1950ms -0.396978503607869
  • Loading branch information
rwstauner committed Jan 21, 2025
1 parent f92f4a7 commit 5d2dc4c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion harness/harness-common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 10 additions & 1 deletion harness/harness.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

diff = (new_value - old_value).to_s.tap do |s|
# Insert comma separators but only in the whole number portion.
i = s.index('.') || s.size
s.insert(i -= 3, ',') while i > 3
# Add a space when positive so that if there is ever a negative
# the first digit will line up.
s.prepend(" ") unless s.start_with?("-")
end

itr_str << " %#{key.size}s" % diff
yjit_stats[key] = new_value
end
Expand Down

0 comments on commit 5d2dc4c

Please sign in to comment.