Created
August 24, 2011 09:19
-
-
Save thisivan/1167670 to your computer and use it in GitHub Desktop.
Method Missing vs Method Compilation
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' | |
# Defined method | |
class ExampleA | |
def test | |
10000 * 10000 | |
end | |
end | |
# Method lookup | |
class ExampleB < ExampleA | |
end | |
# Method Missing | |
class ExampleC | |
def method_missing(name, *args, &block) | |
10000 * 10000 | |
end | |
end | |
class ExampleD | |
end | |
ExampleD.class_eval do | |
def test | |
10000 * 10000 | |
end | |
end | |
Benchmark.bm do |b| | |
b.report { 100000.times { ExampleA.new.test }} | |
b.report { 100000.times { ExampleB.new.test }} | |
b.report { 100000.times { ExampleC.new.test }} | |
b.report { 100000.times { ExampleD.new.test }} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment