-
-
Save jferris/1433935 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 Base | |
def foo | |
true | |
end | |
end | |
class Implicit < Base | |
end | |
class Explicit < Base | |
def foo | |
super | |
end | |
end | |
Benchmark.bmbm do |x| | |
x.report("implicit") do | |
instance = Implicit.new | |
1_000_000.times { instance.foo } | |
end | |
x.report("explicit") do | |
instance = Explicit.new | |
1_000_000.times { instance.foo } | |
end | |
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
Rehearsal -------------------------------------------- | |
implicit 0.130000 0.000000 0.130000 ( 0.133219) | |
explicit 0.190000 0.000000 0.190000 ( 0.187135) | |
----------------------------------- total: 0.320000sec | |
user system total real | |
implicit 0.130000 0.000000 0.130000 ( 0.132344) | |
explicit 0.190000 0.000000 0.190000 ( 0.186354) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment