@@ -109,7 +109,14 @@ class Address
109109 )
110110 end
111111
112+ # Disable GC during benchmark for more stable results
113+ GC.disable
114+
115+ # Run GC before starting to ensure clean state
116+ 3.times { GC.start }
117+
112118 Benchmark.ips do |x|
119+ # Balance between accuracy and speed
113120 x.config(time: 5, warmup: 2)
114121
115122 puts "\n[ Repeated Field Access (10x per iteration) ]"
@@ -139,6 +146,9 @@ class Address
139146 band.name
140147 end
141148 end
149+
150+ # Re-enable GC after benchmark
151+ GC.enable
142152RUBY
143153
144154def parse_results ( text )
@@ -198,20 +208,28 @@ def compare_results(current_file, master_file)
198208 temp_script . write ( BENCHMARK_SCRIPT )
199209 temp_script . close
200210
201- # Run on current branch
202- puts "Running benchmark on current branch..."
211+ # Run on current branch in isolated process
212+ puts "Running benchmark on current branch (this will take ~90 seconds) ..."
203213 current_output = Tempfile . new ( [ 'benchmark_current' , '.txt' ] )
204214 current_output . close
205215
206- system ( "cd #{ repo_root } && ruby #{ temp_script . path } > #{ current_output . path } 2>&1" , exception : true )
216+ # Use bundle exec to ensure proper gem environment, run in fresh process
217+ system ( "cd #{ repo_root } && bundle exec ruby #{ temp_script . path } > #{ current_output . path } 2>&1" , exception : true )
207218
208219 # Switch to master and run
209220 puts "\n Switching to master branch..."
210221 master_output = Tempfile . new ( [ 'benchmark_master' , '.txt' ] )
211222 master_output . close
212223
213224 system ( "git checkout master -q" , exception : true )
214- system ( "cd #{ repo_root } && ruby #{ temp_script . path } > #{ master_output . path } 2>&1" , exception : true )
225+
226+ # Bundle install might be needed if dependencies differ
227+ puts "Ensuring dependencies are installed on master..."
228+ system ( "cd #{ repo_root } && bundle install --quiet > /dev/null 2>&1" )
229+
230+ puts "Running benchmark on master branch (this will take ~90 seconds)..."
231+ # Use bundle exec to ensure proper gem environment, run in fresh process
232+ system ( "cd #{ repo_root } && bundle exec ruby #{ temp_script . path } > #{ master_output . path } 2>&1" , exception : true )
215233
216234 # Switch back to original branch
217235 system ( "git checkout #{ ORIGINAL_BRANCH } -q" , exception : true )
0 commit comments