Sha256: c9396274dd8a9602bc6261bee53d130f832b9e8299b4c6f7285cef098faaa110

Contents?: true

Size: 410 Bytes

Versions: 14

Compression:

Stored size: 410 Bytes

Contents

require 'benchmark'

class Foo
  def bar(a, b)
    a + b
  end

  def baz
    a + b
  end

  def a
    rand(1000_000)
  end

  def b
    rand(1000_000)
  end
end

foo = Foo.new

Benchmark.bm 30 do |x|
  x.report 'original method' do
    1000000.times do |_|
      foo.bar(rand(1_000_000), rand(1_000_000))
    end
  end
  x.report 'shiny new method' do
    1000000.times do |_|
      foo.baz
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
vedeu-0.1.10 test/support/bench.rb
vedeu-0.1.9 test/support/bench.rb
vedeu-0.1.8 test/support/bench.rb
vedeu-0.1.7 test/support/bench.rb
vedeu-0.1.6 test/support/bench.rb
vedeu-0.1.5 test/support/bench.rb
vedeu-0.1.4 test/support/bench.rb
vedeu-0.1.3 test/support/bench.rb
vedeu-0.1.2 test/support/bench.rb
vedeu-0.1.1 test/support/bench.rb
vedeu-0.1.0 test/support/bench.rb
vedeu-0.0.42 test/support/bench.rb
vedeu-0.0.41 test/support/bench.rb
vedeu-0.0.40 test/support/bench.rb