Skip to content

Commit 25c777e

Browse files
committed
[~]
1 parent febcc3e commit 25c777e

1 file changed

Lines changed: 22 additions & 4 deletions

File tree

perf/benchmark_cache_attribute_values.rb

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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
142152
RUBY
143153

144154
def 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 "\nSwitching 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

Comments
 (0)