Skip to content

Commit 6d77587

Browse files
committed
refactor: use inline styles in benchmark SVG
1 parent ad87413 commit 6d77587

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
In the benchmark’s SVG report, there is an unwanted style definition appearing in the automatically inserted GitHub comment. Clean it up and improve the table aesthetics.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
!test/fixtures/*.json
44
!test/benchmarks/fixtures/*.json
55
test/tmp/
6+
reports/
7+
test/benchmarks/tmp/
68
.direnv/
79
.idea/
810
pkg/

test/benchmarks/run_benchmarks.rb

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,16 +177,22 @@ def run_benchmark(name)
177177
height = 40 + row_height * results.size
178178
svg = +"<svg xmlns='http://www.w3.org/2000/svg' width='700' height='#{height}'>\n"
179179
svg << " <foreignObject width='100%' height='100%'>\n"
180-
svg << " <style>table{border-collapse:collapse;font-family:sans-serif;}td,th{border:1px solid #999;padding:4px;text-align:center;}</style>\n"
181-
svg << " <table>\n"
182-
svg << " <thead><tr><th>#{COLUMN_NAMES[:benchmark]}</th><th>#{COLUMN_NAMES[:ruby]}</th><th>#{COLUMN_NAMES[:json]}</th><th>#{COLUMN_NAMES[:capnp]}</th><th>#{COLUMN_NAMES[:pure]}</th></tr></thead>\n"
180+
cell_style = "style='border:1px solid #999;padding:4px;text-align:center;'"
181+
svg << " <table style='border-collapse:collapse;font-family:sans-serif;'>\n"
182+
svg << " <thead><tr>"
183+
svg << "<th #{cell_style}>#{COLUMN_NAMES[:benchmark]}</th>"
184+
svg << "<th #{cell_style}>#{COLUMN_NAMES[:ruby]}</th>"
185+
svg << "<th #{cell_style}>#{COLUMN_NAMES[:json]}</th>"
186+
svg << "<th #{cell_style}>#{COLUMN_NAMES[:capnp]}</th>"
187+
svg << "<th #{cell_style}>#{COLUMN_NAMES[:pure]}</th></tr></thead>\n"
183188
svg << " <tbody>\n"
184-
results.each do |r|
189+
results.each_with_index do |r, idx|
190+
row_style = idx.odd? ? " style='background:#f0f0f0;'" : ''
185191
ruby_s = "#{r[:ruby_ms]}ms"
186192
json_s = "#{r[:native_ok] ? '✓' : '✗'} #{r[:native_ms]}ms"
187193
capnp_s = "#{r[:native_bin_ms]}ms"
188194
pure_s = "#{r[:pure_ok] ? '✓' : '✗'} #{r[:pure_ms]}ms"
189-
svg << " <tr><td>#{r[:name]}</td><td>#{ruby_s}</td><td>#{json_s}</td><td>#{capnp_s}</td><td>#{pure_s}</td></tr>\n"
195+
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"
190196
end
191197
svg << " </tbody>\n"
192198
svg << " </table>\n"

0 commit comments

Comments
 (0)