Skip to content

Instantly share code, notes, and snippets.

@akshay-vishnoi
Created November 29, 2013 13:34

Revisions

  1. akshay-vishnoi created this gist Nov 29, 2013.
    35 changes: 35 additions & 0 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    # ruby 2.0.0-p247
    require 'benchmark'

    def old_method(&block)
    yield
    end

    def new_method
    yield
    end

    TIMES = 500_000
    Benchmark.bmbm do |b|
    b.report('old') do
    TIMES.times do
    old_method { 'abc' }
    end
    end

    b.report('new') do
    TIMES.times do
    new_method { 'abc' }
    end
    end
    end


    Rehearsal ---------------------------------------
    old 0.590000 0.020000 0.610000 ( 0.615266)
    new 0.160000 0.000000 0.160000 ( 0.159566)
    ------------------------------ total: 0.770000sec

    user system total real
    old 0.570000 0.020000 0.590000 ( 0.584801)
    new 0.130000 0.000000 0.130000 ( 0.131258)