Created
December 5, 2011 01:47
-
-
Save sikachu/1431961 to your computer and use it in GitHub Desktop.
Compare between not define a method in subclass and define a method in subclass and call #super
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[~] 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) | |
[~] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment