Skip to content

Instantly share code, notes, and snippets.

@sikachu
Created December 5, 2011 01:47
Show Gist options
  • Select an option

  • Save sikachu/1431961 to your computer and use it in GitHub Desktop.

Select an option

Save sikachu/1431961 to your computer and use it in GitHub Desktop.

Revisions

  1. sikachu created this gist Dec 5, 2011.
    36 changes: 36 additions & 0 deletions benchmark.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    require 'benchmark'

    class A0
    def foo
    true
    end
    end

    (1..1000).each do |n|
    eval <<-RUBY
    class A#{n} < A#{n-1}
    end
    RUBY
    end

    class B0
    def foo
    true
    end
    end

    (1..1000).each do |n|
    eval <<-RUBY
    class B#{n} < B#{n-1}
    def foo
    super
    end
    end
    RUBY
    end


    Benchmark.bmbm do |x|
    x.report("implicit") { A1000.new.foo }
    x.report("explicit") { B1000.new.foo }
    end
    10 changes: 10 additions & 0 deletions result
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    [~] ruby benchmark.rb
    Rehearsal --------------------------------------------
    implicit 0.010000 0.000000 0.010000 ( 0.000501)
    explicit 0.000000 0.000000 0.000000 ( 0.008302)
    ----------------------------------- total: 0.010000sec

    user system total real
    implicit 0.000000 0.000000 0.000000 ( 0.000139)
    explicit 0.010000 0.000000 0.010000 ( 0.007057)
    [~]