@@ -43,12 +43,25 @@ def run(ruby:, ruby_description:)
4343 env = benchmark_env ( ruby )
4444 caller_json_path = ENV [ "RESULT_JSON_PATH" ]
4545
46+ # Capture quiet setting before entering unbundled env (which clears ENV)
47+ quiet = ENV [ 'BENCHMARK_QUIET' ] == '1'
48+
4649 benchmark_entries . each_with_index do |entry , idx |
4750 puts ( "Running benchmark \" #{ entry . name } \" (#{ idx +1 } /#{ benchmark_entries . length } )" )
4851
4952 result_json_path = caller_json_path || File . join ( out_path , "temp#{ Process . pid } .json" )
5053 cmd_prefix = base_cmd ( ruby_description , entry . name )
51- result = run_single_benchmark ( entry . script_path , result_json_path , ruby , cmd_prefix , env , entry . name )
54+
55+ # Clear project-level Bundler environment so benchmarks run in a clean context.
56+ # Benchmarks that need Bundler (e.g., railsbench) set up their own via use_gemfile.
57+ # This is important when running tests under `bundle exec rake test`.
58+ result = if defined? ( Bundler )
59+ Bundler . with_unbundled_env do
60+ run_single_benchmark ( entry . script_path , result_json_path , ruby , cmd_prefix , env , entry . name , quiet : quiet )
61+ end
62+ else
63+ run_single_benchmark ( entry . script_path , result_json_path , ruby , cmd_prefix , env , entry . name , quiet : quiet )
64+ end
5265
5366 if result [ :success ]
5467 bench_data [ entry . name ] = process_benchmark_result ( result_json_path , result [ :command ] , delete_file : !caller_json_path )
@@ -120,7 +133,7 @@ def filter_entries(entries, categories:, name_filters:, excludes:, directory_map
120133 entries . select { |entry | filter . match? ( entry . name ) }
121134 end
122135
123- def run_single_benchmark ( script_path , result_json_path , ruby , cmd_prefix , env , benchmark_name )
136+ def run_single_benchmark ( script_path , result_json_path , ruby , cmd_prefix , env , benchmark_name , quiet : false )
124137 # Fix for jruby/jruby#7394 in JRuby 9.4.2.0
125138 script_path = File . expand_path ( script_path )
126139
@@ -141,7 +154,7 @@ def run_single_benchmark(script_path, result_json_path, ruby, cmd_prefix, env, b
141154 ] . compact
142155
143156 # Do the benchmarking
144- result = BenchmarkRunner . check_call ( cmd . shelljoin , env : env , raise_error : false )
157+ result = BenchmarkRunner . check_call ( cmd . shelljoin , env : env , raise_error : false , quiet : quiet )
145158 result [ :command ] = cmd . shelljoin
146159 result
147160 ensure
@@ -177,6 +190,12 @@ def benchmark_env(ruby)
177190 end
178191 end
179192
193+ # Pass benchmark configuration env vars to subprocess.
194+ # These may be set after bundler loads, so they'd be lost with with_unbundled_env.
195+ [ "WARMUP_ITRS" , "MIN_BENCH_ITRS" , "MIN_BENCH_TIME" , "YJIT_BENCH_STATS" , "ZJIT_BENCH_STATS" ] . each do |var |
196+ env [ var ] = ENV [ var ] if ENV . key? ( var )
197+ end
198+
180199 env
181200 end
182201
0 commit comments