Sha256: 22a2f76daaeafe582cf2fef706de5e3b8e68f93adf961c8edd39187559a8b5a7

Contents?: true

Size: 1.29 KB

Versions: 21

Compression:

Stored size: 1.29 KB

Contents

require 'benchmark'

n = 100_000

def call_block(&block)
  block.call
end

def yield_control
  yield
end

Benchmark.benchmark do |bm|
  puts "#{n} times - ruby #{RUBY_VERSION}"

  puts
  puts "eval"

  3.times do
    bm.report do
      n.times do
        eval("2 + 3")
      end
    end
  end

  puts
  puts "call block"

  3.times do
    bm.report do
      n.times do
        call_block { 2 + 3 }
      end
    end
  end

  puts
  puts "yield"

  3.times do
    bm.report do
      n.times do
        yield_control { 2 + 3 }
      end
    end
  end

  puts
  puts "exec"

  3.times do
    bm.report do
      n.times do
        2 + 3
      end
    end
  end
end

# 100000 times - ruby 1.9.3
#
# eval
#    0.870000   0.010000   0.880000 (  0.877762)
#    0.890000   0.000000   0.890000 (  0.891142)
#    0.890000   0.000000   0.890000 (  0.896365)
#
# call block
#    0.120000   0.010000   0.130000 (  0.136322)
#    0.130000   0.010000   0.140000 (  0.138608)
#    0.130000   0.000000   0.130000 (  0.129931)
#
# yield
#    0.020000   0.000000   0.020000 (  0.020412)
#    0.010000   0.000000   0.010000 (  0.017926)
#    0.020000   0.000000   0.020000 (  0.025740)
#
# exec
#    0.010000   0.000000   0.010000 (  0.009935)
#    0.010000   0.000000   0.010000 (  0.011588)
#    0.010000   0.000000   0.010000 (  0.010613)

Version data entries

21 entries across 21 versions & 2 rubygems

Version Path
opal-rspec-1.1.0.alpha3 rspec-core/upstream/benchmarks/call_v_yield.rb
opal-rspec-1.1.0.alpha2 rspec-core/upstream/benchmarks/call_v_yield.rb
opal-rspec-1.1.0.alpha1 rspec-core/upstream/benchmarks/call_v_yield.rb
opal-rspec-1.0.0 rspec-core/upstream/benchmarks/call_v_yield.rb
opal-rspec-1.0.0.alpha1 rspec-core/upstream/benchmarks/call_v_yield.rb
opal-rspec-0.8.0 rspec-core/upstream/benchmarks/call_v_yield.rb
opal-rspec-0.8.0.alpha3 rspec-core/upstream/benchmarks/call_v_yield.rb
opal-rspec-0.8.0.alpha2 rspec-core/upstream/benchmarks/call_v_yield.rb
opal-rspec-0.8.0.alpha1 rspec-core/upstream/benchmarks/call_v_yield.rb
opal-rspec-0.7.1 rspec-core/upstream/benchmarks/call_v_yield.rb
opal-rspec-0.7.0 rspec-core/upstream/benchmarks/call_v_yield.rb
opal-rspec-0.6.2 rspec-core/benchmarks/call_v_yield.rb
opal-rspec-0.7.0.rc.2 rspec-core/upstream/benchmarks/call_v_yield.rb
opal-rspec-0.6.1 rspec-core/benchmarks/call_v_yield.rb
opal-rspec-0.6.0 rspec-core/benchmarks/call_v_yield.rb
opal-rspec-0.6.0.beta1 rspec-core/benchmarks/call_v_yield.rb
opal-connect-rspec-0.5.0 rspec-core/benchmarks/call_v_yield.rb
opal-rspec-0.5.0 rspec-core/benchmarks/call_v_yield.rb
opal-rspec-0.5.0.beta3 rspec-core/benchmarks/call_v_yield.rb
opal-rspec-0.5.0.beta2 rspec-core/benchmarks/call_v_yield.rb