Skip to content

Commit c357a87

Browse files
committed
Simplify benchmark sorting by using sort_by with category priority
1 parent 03fafdf commit c357a87

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

lib/results_table_builder.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,15 @@ def compute_bench_names
154154

155155
# Sort benchmarks with headlines first, then others, then micro
156156
def sort_benchmarks(bench_names, metadata)
157-
headline_benchmarks = metadata.select { |_, meta| meta['category'] == 'headline' }.keys
158-
micro_benchmarks = metadata.select { |_, meta| meta['category'] == 'micro' }.keys
157+
bench_names.sort_by { |name| [category_priority(name, metadata), name] }
158+
end
159159

160-
headline_names, bench_names = bench_names.partition { |name| headline_benchmarks.include?(name) }
161-
micro_names, other_names = bench_names.partition { |name| micro_benchmarks.include?(name) }
162-
headline_names.sort + other_names.sort + micro_names.sort
160+
def category_priority(bench_name, metadata)
161+
category = metadata.dig(bench_name, 'category') || 'other'
162+
case category
163+
when 'headline' then 0
164+
when 'micro' then 2
165+
else 1
166+
end
163167
end
164168
end

0 commit comments

Comments
 (0)