Skip to content

Instantly share code, notes, and snippets.

@jferris
Forked from sikachu/benchmark.rb
Created December 5, 2011 15:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jferris/1433935 to your computer and use it in GitHub Desktop.
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
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
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