Created
October 18, 2012 20:37
-
-
Save localshred/3914546 to your computer and use it in GitHub Desktop.
I was wondering how fast the different dynamic method dispatching options in ruby are. After doing this, I guess I shouldn't be surprised. My assumption is that the method object call is slower since we're actually instantiating an object..
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 TestMethodCall | |
def test | |
100 + 100 | |
end | |
end | |
Benchmark.benchmark("Dynamic method calling\n") do |x| | |
instance = TestMethodCall.new | |
x.report('__send__') do | |
1_000_000.times { instance.__send__(:test) } | |
end | |
x.report('method object call') do | |
1_000_000.times { instance.method(:test).call } | |
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
Dynamic method calling | |
__send__ 0.220000 0.000000 0.220000 ( 0.234082) | |
method object call 0.900000 0.060000 0.960000 ( 1.474704) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment