88require 'yaml'
99require 'rbconfig'
1010require_relative 'benchmark_filter'
11+ require_relative 'benchmark_runner'
1112
1213# BenchmarkSuite runs a collection of benchmarks and collects their results
1314class BenchmarkSuite
@@ -17,7 +18,7 @@ class BenchmarkSuite
1718 RACTOR_CATEGORY = "ractor"
1819 RACTOR_HARNESS = "harness-ractor"
1920
20- attr_reader :ruby , :ruby_description , :categories , :name_filters , :out_path , :harness , :pre_init , :no_pinning
21+ attr_reader :ruby , :ruby_description , :categories , :name_filters , :out_path , :harness , :pre_init , :no_pinning , :bench_dir , :ractor_bench_dir
2122
2223 def initialize ( ruby :, ruby_description :, categories :, name_filters :, out_path :, harness :, pre_init : nil , no_pinning : false )
2324 @ruby = ruby
@@ -29,6 +30,15 @@ def initialize(ruby:, ruby_description:, categories:, name_filters:, out_path:,
2930 @pre_init = pre_init ? expand_pre_init ( pre_init ) : nil
3031 @no_pinning = no_pinning
3132 @ractor_only = ( categories == RACTOR_ONLY_CATEGORY )
33+
34+ @bench_dir = BENCHMARKS_DIR
35+ @ractor_bench_dir = RACTOR_BENCHMARKS_DIR
36+
37+ if @ractor_only
38+ @bench_dir = @ractor_bench_dir
39+ @harness = RACTOR_HARNESS
40+ @categories = [ ]
41+ end
3242 end
3343
3444 # Run all the benchmarks and record execution times
@@ -37,33 +47,6 @@ def run
3747 bench_data = { }
3848 bench_failures = { }
3949
40- bench_dir = BENCHMARKS_DIR
41- ractor_bench_dir = RACTOR_BENCHMARKS_DIR
42-
43- if @racktor_only
44- bench_dir = ractor_bench_dir
45- @harness = RACTOR_HARNESS
46- @categories = [ ]
47- end
48-
49- bench_file_grouping = { }
50-
51- # Get the list of benchmark files/directories matching name filters
52- filter = benchmark_filter ( categories : categories , name_filters : name_filters )
53- bench_file_grouping [ bench_dir ] = Dir . children ( bench_dir ) . sort . filter do |entry |
54- filter . match? ( entry )
55- end
56-
57- if categories == [ RACTOR_CATEGORY ]
58- # We ignore the category filter here because everything in the
59- # benchmarks-ractor directory should be included when we're benchmarking the
60- # Ractor category
61- ractor_filter = benchmark_filter ( categories : [ ] , name_filters : name_filters )
62- bench_file_grouping [ ractor_bench_dir ] = Dir . children ( ractor_bench_dir ) . sort . filter do |entry |
63- ractor_filter . match? ( entry )
64- end
65- end
66-
6750 bench_file_grouping . each do |bench_dir , bench_files |
6851 bench_files . each_with_index do |entry , idx |
6952 bench_name = entry . gsub ( '.rb' , '' )
@@ -140,6 +123,30 @@ def run
140123
141124 private
142125
126+ def bench_file_grouping
127+ bench_file_grouping = { }
128+
129+ # Get the list of benchmark files/directories matching name filters
130+ filter = benchmark_filter ( categories : categories , name_filters : name_filters )
131+ bench_file_grouping [ bench_dir ] = filtered_bench_entries ( bench_dir , filter )
132+
133+ if categories == [ RACTOR_CATEGORY ]
134+ # We ignore the category filter here because everything in the
135+ # benchmarks-ractor directory should be included when we're benchmarking the
136+ # Ractor category
137+ ractor_filter = benchmark_filter ( categories : [ ] , name_filters : name_filters )
138+ bench_file_grouping [ ractor_bench_dir ] = filtered_bench_entries ( ractor_bench_dir , ractor_filter )
139+ end
140+
141+ bench_file_grouping
142+ end
143+
144+ def filtered_bench_entries ( dir , filter )
145+ Dir . children ( dir ) . sort . filter do |entry |
146+ filter . match? ( entry )
147+ end
148+ end
149+
143150 def benchmark_filter ( categories :, name_filters :)
144151 @benchmark_filter ||= { }
145152 key = [ categories , name_filters ]
0 commit comments