Skip to content

Commit

Permalink
Disable garbage collection during ips benchmarks (#83)
Browse files Browse the repository at this point in the history
So that GC doesn't interfere with results.
  • Loading branch information
gonzedge authored Dec 3, 2024
1 parent c0fc6c1 commit f496495
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tasks/ips.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# frozen_string_literal: true

namespace :ips do
task :assign_variable_vs_not do
compare_assign_variable_vs_not
end

task :string_slice_vs_brackets do
compare_string_slice_vs_brackets
end
Expand Down Expand Up @@ -65,12 +69,31 @@
def compare
require 'benchmark/ips'
Benchmark.ips do |bm|
::GC.start
::GC.disable
yield bm
::GC.enable

bm.compare!
end
end

def compare_assign_variable_vs_not
compare do |bm|
bm.config time: 20, warmup: 2
a = 1

bm.report 'assign var' do
b = 2
a + b
end

bm.report 'no var' do
a + 2
end
end
end

def compare_string_slice_vs_brackets
compare do |bm|
bm.config time: 20, warmup: 2
Expand Down

0 comments on commit f496495

Please sign in to comment.