Skip to content

Commit 20ac032

Browse files
committed
Combine measurements and stddev in one column
1 parent 43dc4a5 commit 20ac032

File tree

2 files changed

+37
-23
lines changed

2 files changed

+37
-23
lines changed

lib/results_table_builder.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def build_header
3939
header = ["bench"]
4040

4141
@executable_names.each do |name|
42-
header << "#{name} (ms)" << "stddev (%)"
42+
header << "#{name} (ms)"
4343
header << "RSS (MiB)" if @include_rss
4444
end
4545

@@ -67,7 +67,7 @@ def build_format
6767
format = ["%s"]
6868

6969
@executable_names.each do |_name|
70-
format << "%.1f" << "%.1f"
70+
format << "%s"
7171
format << "%.1f" if @include_rss
7272
end
7373

@@ -110,19 +110,21 @@ def build_row(bench_name)
110110
end
111111

112112
def build_base_columns(row, base_t, base_rss)
113-
row << mean(base_t)
114-
row << stddev_percent(base_t)
113+
row << format_time_with_stddev(base_t)
115114
row << base_rss if @include_rss
116115
end
117116

118117
def build_comparison_columns(row, other_ts, other_rsss)
119118
other_ts.zip(other_rsss).each do |other_t, other_rss|
120-
row << mean(other_t)
121-
row << stddev_percent(other_t)
119+
row << format_time_with_stddev(other_t)
122120
row << other_rss if @include_rss
123121
end
124122
end
125123

124+
def format_time_with_stddev(values)
125+
"%.1f ± %.1f%%" % [mean(values), stddev_percent(values)]
126+
end
127+
126128
def build_ratio_columns(row, base_t0, other_t0s, base_t, other_ts)
127129
ratio_1sts = other_t0s.map { |other_t0| base_t0 / other_t0 }
128130
row.concat(ratio_1sts)

test/results_table_builder_test.rb

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,25 @@
5656

5757
table, format = builder.build
5858

59-
assert_equal ['bench', 'ruby (ms)', 'stddev (%)', 'ruby-yjit (ms)', 'stddev (%)', 'ruby-yjit 1st itr', 'ruby/ruby-yjit'], table[0]
59+
assert_equal ['bench', 'ruby (ms)', 'ruby-yjit (ms)', 'ruby-yjit 1st itr', 'ruby/ruby-yjit'], table[0]
6060

61-
assert_equal ['%s', '%.1f', '%.1f', '%.1f', '%.1f', '%.3f', '%s'], format
61+
assert_equal ['%s', '%s', '%s', '%.3f', '%s'], format
6262

6363
assert_equal 'fib', table[1][0]
64-
assert_in_delta 100.0, table[1][1], 1.0
65-
assert_in_delta 50.0, table[1][3], 1.0
66-
assert_in_delta 2.0, table[1][5], 0.1
67-
assert_match(/^2\.0\d+/, table[1][6])
64+
65+
m = table[1][1].match(/\A(\d+\.\d) ± (\d+\.\d)%\z/)
66+
assert m
67+
assert_in_delta 100.0, m[1].to_f, 1.0
68+
69+
m = table[1][2].match(/\A(\d+\.\d) ± (\d+\.\d)%\z/)
70+
assert m
71+
assert_in_delta 50.0, m[1].to_f, 1.0
72+
73+
assert_in_delta 2.0, table[1][3], 0.1
74+
75+
m = table[1][4].match(/\A(\d+\.\d+)/)
76+
assert m
77+
assert_in_delta 2.0, m[1].to_f, 0.1
6878
end
6979

7080
it 'includes RSS columns when include_rss is true' do
@@ -88,9 +98,9 @@
8898
table, format = builder.build
8999

90100
# No RSS ratio column with a single executable
91-
assert_equal ['bench', 'ruby (ms)', 'stddev (%)', 'RSS (MiB)'], table[0]
92-
assert_equal ['%s', '%.1f', '%.1f', '%.1f'], format
93-
assert_in_delta 10.0, table[1][3], 0.1
101+
assert_equal ['bench', 'ruby (ms)', 'RSS (MiB)'], table[0]
102+
assert_equal ['%s', '%s', '%.1f'], format
103+
assert_in_delta 10.0, table[1][2], 0.1
94104
end
95105

96106
it 'includes RSS ratio columns when include_rss is true with multiple executables' do
@@ -122,15 +132,15 @@
122132

123133
expected_header = [
124134
'bench',
125-
'ruby (ms)', 'stddev (%)', 'RSS (MiB)',
126-
'ruby-yjit (ms)', 'stddev (%)', 'RSS (MiB)',
135+
'ruby (ms)', 'RSS (MiB)',
136+
'ruby-yjit (ms)', 'RSS (MiB)',
127137
'ruby-yjit 1st itr',
128138
'ruby/ruby-yjit',
129139
'RSS ruby/ruby-yjit'
130140
]
131141
assert_equal expected_header, table[0]
132142

133-
expected_format = ['%s', '%.1f', '%.1f', '%.1f', '%.1f', '%.1f', '%.1f', '%.3f', '%s', '%.3f']
143+
expected_format = ['%s', '%s', '%.1f', '%s', '%.1f', '%.3f', '%s', '%.3f']
134144
assert_equal expected_format, format
135145

136146
# RSS ratio: 10 MiB / 20 MiB = 0.5
@@ -209,17 +219,17 @@
209219

210220
expected_header = [
211221
'bench',
212-
'ruby (ms)', 'stddev (%)',
213-
'ruby-yjit (ms)', 'stddev (%)',
214-
'ruby-rjit (ms)', 'stddev (%)',
222+
'ruby (ms)',
223+
'ruby-yjit (ms)',
224+
'ruby-rjit (ms)',
215225
'ruby-yjit 1st itr',
216226
'ruby-rjit 1st itr',
217227
'ruby/ruby-yjit',
218228
'ruby/ruby-rjit'
219229
]
220230
assert_equal expected_header, table[0]
221231

222-
expected_format = ['%s', '%.1f', '%.1f', '%.1f', '%.1f', '%.1f', '%.1f', '%.3f', '%.3f', '%s', '%s']
232+
expected_format = ['%s', '%s', '%s', '%s', '%.3f', '%.3f', '%s', '%s']
223233
assert_equal expected_format, format
224234
end
225235

@@ -245,7 +255,9 @@
245255

246256
assert_equal 2, table.length
247257
assert_equal 'fib', table[1][0]
248-
assert_in_delta 100.0, table[1][1], 5.0
258+
m = table[1][1].match(/\A(\d+\.\d) ± (\d+\.\d)%\z/)
259+
assert m
260+
assert_in_delta 100.0, m[1].to_f, 5.0
249261
end
250262

251263
it 'sorts benchmarks with headlines first, then others, then micro' do

0 commit comments

Comments
 (0)