Skip to content

Commit f03bf7d

Browse files
committed
feat(benchmarks): add comma formatting
1 parent a9bf567 commit f03bf7d

File tree

5 files changed

+69
-14
lines changed

5 files changed

+69
-14
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
In the console and svg benchmarks, format the numbers with commas for better readability. Use rubocop for linting. Ensure all software used in the just files is installed in the GitHub workflows.

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ gem "codetracer-pure-ruby-recorder", path: "gems/codetracer-pure-ruby-recorder"
88
# Development and debugging gems (optional - install separately if needed)
99
# gem "debug", "~> 1.7" # Ruby debugging with rdbg
1010
# gem "pry", "~> 0.14" # Interactive debugging and REPL
11+
12+
gem "rubocop", "~> 1.77", :group => :development

Gemfile.lock

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,55 @@
1+
PATH
2+
remote: gems/codetracer-pure-ruby-recorder
3+
specs:
4+
codetracer-pure-ruby-recorder (0.1.0)
5+
6+
PATH
7+
remote: gems/codetracer-ruby-recorder
8+
specs:
9+
codetracer-ruby-recorder (0.1.0)
10+
111
GEM
212
remote: https://rubygems.org/
313
specs:
14+
ast (2.4.3)
15+
json (2.12.2)
16+
language_server-protocol (3.17.0.5)
17+
lint_roller (1.1.0)
18+
parallel (1.27.0)
19+
parser (3.3.8.0)
20+
ast (~> 2.4.1)
21+
racc
22+
prism (1.4.0)
23+
racc (1.8.1)
24+
rainbow (3.1.1)
25+
regexp_parser (2.10.0)
26+
rubocop (1.77.0)
27+
json (~> 2.3)
28+
language_server-protocol (~> 3.17.0.2)
29+
lint_roller (~> 1.1.0)
30+
parallel (~> 1.10)
31+
parser (>= 3.3.0.2)
32+
rainbow (>= 2.2.2, < 4.0)
33+
regexp_parser (>= 2.9.3, < 3.0)
34+
rubocop-ast (>= 1.45.1, < 2.0)
35+
ruby-progressbar (~> 1.7)
36+
unicode-display_width (>= 2.4.0, < 4.0)
37+
rubocop-ast (1.45.1)
38+
parser (>= 3.3.7.2)
39+
prism (~> 1.4)
40+
ruby-progressbar (1.13.0)
41+
unicode-display_width (3.1.4)
42+
unicode-emoji (~> 4.0, >= 4.0.4)
43+
unicode-emoji (4.0.4)
444

545
PLATFORMS
646
ruby
747
x86_64-linux
848

949
DEPENDENCIES
50+
codetracer-pure-ruby-recorder!
51+
codetracer-ruby-recorder!
52+
rubocop (~> 1.77)
1053

1154
BUNDLED WITH
12-
2.5.22
55+
2.4.19

Justfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ lint-nix:
3030
if command -v nixfmt >/dev/null; then find . -name '*.nix' -print0 | xargs -0 nixfmt --check; fi
3131

3232
lint-ruby:
33-
find . -name '*.rb' -print0 | xargs -0 -n 1 ruby -wc
33+
if command -v bundle >/dev/null && bundle exec rubocop -v >/dev/null 2>&1; then bundle exec rubocop; else echo "rubocop not available; skipping"; fi
3434

3535
lint:
3636
just lint-rust

test/benchmarks/run_benchmarks.rb

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
pure: 'JSON (PureRuby)'
2222
}.freeze
2323

24+
# Format integer with comma separators for readability
25+
def comma(n)
26+
n.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1,').reverse
27+
end
28+
2429
options = { write_report: WRITE_REPORT_DEFAULT }
2530
OptionParser.new do |opts|
2631
opts.banner = 'Usage: ruby run_benchmarks.rb GLOB [options]'
@@ -128,10 +133,14 @@ def run_benchmark(name)
128133
if options[:write_report] == 'console'
129134
# Determine column widths with padding
130135
name_w = [COLUMN_NAMES[:benchmark].length, *results.map { |r| r[:name].length }].max + 2
131-
ruby_w = [COLUMN_NAMES[:ruby].length, *results.map { |r| "#{r[:ruby_ms]}ms".length }].max + 2
132-
json_w = [COLUMN_NAMES[:json].length, *results.map { |r| "#{r[:native_ok] ? '✓' : '✗'} #{r[:native_ms]}ms #{r[:native_bytes]}B".length }].max + 2
133-
capnp_w = [COLUMN_NAMES[:capnp].length, *results.map { |r| "#{r[:native_bin_ms]}ms #{r[:native_bin_bytes]}B".length }].max + 2
134-
pure_w = [COLUMN_NAMES[:pure].length, *results.map { |r| "#{r[:pure_ok] ? '✓' : '✗'} #{r[:pure_ms]}ms #{r[:pure_bytes]}B".length }].max + 2
136+
ruby_w = [COLUMN_NAMES[:ruby].length,
137+
*results.map { |r| "#{comma(r[:ruby_ms])}ms".length }].max + 2
138+
json_w = [COLUMN_NAMES[:json].length,
139+
*results.map { |r| "#{r[:native_ok] ? '✓' : '✗'} #{comma(r[:native_ms])}ms #{comma(r[:native_bytes])}B".length }].max + 2
140+
capnp_w = [COLUMN_NAMES[:capnp].length,
141+
*results.map { |r| "#{comma(r[:native_bin_ms])}ms #{comma(r[:native_bin_bytes])}B".length }].max + 2
142+
pure_w = [COLUMN_NAMES[:pure].length,
143+
*results.map { |r| "#{r[:pure_ok] ? '✓' : '✗'} #{comma(r[:pure_ms])}ms #{comma(r[:pure_bytes])}B".length }].max + 2
135144

136145
total_width = name_w + ruby_w + json_w + capnp_w + pure_w + 5
137146

@@ -142,10 +151,10 @@ def run_benchmark(name)
142151

143152
# Rows
144153
results.each do |r|
145-
ruby_s = "#{r[:ruby_ms]}ms"
146-
json_s = "#{r[:native_ok] ? '✓' : '✗'} #{r[:native_ms]}ms #{r[:native_bytes]}B"
147-
capnp_s = "#{r[:native_bin_ms]}ms #{r[:native_bin_bytes]}B"
148-
pure_s = "#{r[:pure_ok] ? '✓' : '✗'} #{r[:pure_ms]}ms #{r[:pure_bytes]}B"
154+
ruby_s = "#{comma(r[:ruby_ms])}ms"
155+
json_s = "#{r[:native_ok] ? '✓' : '✗'} #{comma(r[:native_ms])}ms #{comma(r[:native_bytes])}B"
156+
capnp_s = "#{comma(r[:native_bin_ms])}ms #{comma(r[:native_bin_bytes])}B"
157+
pure_s = "#{r[:pure_ok] ? '✓' : '✗'} #{comma(r[:pure_ms])}ms #{comma(r[:pure_bytes])}B"
149158
printf "| %-#{name_w-2}s | %#{ruby_w-2}s | %-#{json_w-2}s | %#{capnp_w-2}s | %-#{pure_w-2}s |\n", r[:name], ruby_s, json_s, capnp_s, pure_s
150159
end
151160
puts "=" * total_width
@@ -195,10 +204,10 @@ def run_benchmark(name)
195204
svg << " <tbody>\n"
196205
results.each_with_index do |r, idx|
197206
row_style = idx.odd? ? " style='background:#f0f0f0;'" : ''
198-
ruby_s = "#{r[:ruby_ms]}ms"
199-
json_s = "#{r[:native_ok] ? '✓' : '✗'} #{r[:native_ms]}ms #{r[:native_bytes]}B"
200-
capnp_s = "#{r[:native_bin_ms]}ms #{r[:native_bin_bytes]}B"
201-
pure_s = "#{r[:pure_ok] ? '✓' : '✗'} #{r[:pure_ms]}ms #{r[:pure_bytes]}B"
207+
ruby_s = "#{comma(r[:ruby_ms])}ms"
208+
json_s = "#{r[:native_ok] ? '✓' : '✗'} #{comma(r[:native_ms])}ms #{comma(r[:native_bytes])}B"
209+
capnp_s = "#{comma(r[:native_bin_ms])}ms #{comma(r[:native_bin_bytes])}B"
210+
pure_s = "#{r[:pure_ok] ? '✓' : '✗'} #{comma(r[:pure_ms])}ms #{comma(r[:pure_bytes])}B"
202211
svg << " <tr#{row_style}><td #{cell_style}>#{r[:name]}</td><td #{cell_style}>#{ruby_s}</td><td #{cell_style}>#{json_s}</td><td #{cell_style}>#{capnp_s}</td><td #{cell_style}>#{pure_s}</td></tr>\n"
203212
end
204213
svg << " </tbody>\n"

0 commit comments

Comments
 (0)