Skip to content

Commit 0f51b4b

Browse files
committed
feat(bench): report trace sizes
include trace file sizes in console, JSON and SVG reports for benchmarks
1 parent 2e7caed commit 0f51b4b

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
In the benchmark reports produced by 'just bench', include the size of the produced trace files. Do this for all report types.

test/benchmarks/run_benchmarks.rb

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ def run_benchmark(name)
9191
native_trace = File.join(native_dir, 'trace.json')
9292
# TODO: Re-enable strict comparison: results[:native_ok] = traces_equal?(fixture, native_trace)
9393
results[:native_ok] = trace_valid?(native_trace)
94+
results[:native_bytes] = File.exist?(native_trace) ? File.size(native_trace) : 0
9495

9596
native_bin_dir = File.join(TMP_DIR, name, 'native_bin')
9697
FileUtils.mkdir_p(native_bin_dir)
@@ -100,7 +101,9 @@ def run_benchmark(name)
100101
raise 'Native binary trace failed' unless $?.success?
101102
end
102103
results[:native_bin_ms] = (elapsed * 1000).round
103-
results[:native_bin_ok] = File.exist?(File.join(native_bin_dir, 'trace.bin'))
104+
native_bin_trace = File.join(native_bin_dir, 'trace.bin')
105+
results[:native_bin_ok] = File.exist?(native_bin_trace)
106+
results[:native_bin_bytes] = File.exist?(native_bin_trace) ? File.size(native_bin_trace) : 0
104107

105108
pure_dir = File.join(TMP_DIR, name, 'pure')
106109
FileUtils.mkdir_p(pure_dir)
@@ -113,6 +116,7 @@ def run_benchmark(name)
113116
pure_trace = File.join(pure_dir, 'trace.json')
114117
# TODO: Re-enable strict comparison: results[:pure_ok] = traces_equal?(fixture, pure_trace)
115118
results[:pure_ok] = trace_valid?(pure_trace)
119+
results[:pure_bytes] = File.exist?(pure_trace) ? File.size(pure_trace) : 0
116120

117121
results
118122
end
@@ -125,9 +129,9 @@ def run_benchmark(name)
125129
# Determine column widths with padding
126130
name_w = [COLUMN_NAMES[:benchmark].length, *results.map { |r| r[:name].length }].max + 2
127131
ruby_w = [COLUMN_NAMES[:ruby].length, *results.map { |r| "#{r[:ruby_ms]}ms".length }].max + 2
128-
json_w = [COLUMN_NAMES[:json].length, *results.map { |r| "#{r[:native_ok] ? '✓' : '✗'} #{r[:native_ms]}ms".length }].max + 2
129-
capnp_w = [COLUMN_NAMES[:capnp].length, *results.map { |r| "#{r[:native_bin_ms]}ms".length }].max + 2
130-
pure_w = [COLUMN_NAMES[:pure].length, *results.map { |r| "#{r[:pure_ok] ? '✓' : '✗'} #{r[:pure_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
131135

132136
total_width = name_w + ruby_w + json_w + capnp_w + pure_w + 5
133137

@@ -139,9 +143,9 @@ def run_benchmark(name)
139143
# Rows
140144
results.each do |r|
141145
ruby_s = "#{r[:ruby_ms]}ms"
142-
json_s = "#{r[:native_ok] ? '✓' : '✗'} #{r[:native_ms]}ms"
143-
capnp_s = "#{r[:native_bin_ms]}ms"
144-
pure_s = "#{r[:pure_ok] ? '✓' : '✗'} #{r[:pure_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"
145149
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
146150
end
147151
puts "=" * total_width
@@ -165,9 +169,12 @@ def run_benchmark(name)
165169
benchmark: r[:name],
166170
ruby_ms: r[:ruby_ms],
167171
native_ms: r[:native_ms],
172+
native_bytes: r[:native_bytes],
168173
native_ok: r[:native_ok],
169174
native_bin_ms: r[:native_bin_ms],
175+
native_bin_bytes: r[:native_bin_bytes],
170176
pure_ms: r[:pure_ms],
177+
pure_bytes: r[:pure_bytes],
171178
pure_ok: r[:pure_ok]
172179
}
173180
end
@@ -189,9 +196,9 @@ def run_benchmark(name)
189196
results.each_with_index do |r, idx|
190197
row_style = idx.odd? ? " style='background:#f0f0f0;'" : ''
191198
ruby_s = "#{r[:ruby_ms]}ms"
192-
json_s = "#{r[:native_ok] ? '✓' : '✗'} #{r[:native_ms]}ms"
193-
capnp_s = "#{r[:native_bin_ms]}ms"
194-
pure_s = "#{r[:pure_ok] ? '✓' : '✗'} #{r[:pure_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"
195202
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"
196203
end
197204
svg << " </tbody>\n"

0 commit comments

Comments
 (0)