Created
December 28, 2016 02:51
-
-
Save davidcelis/066e1f83dc914e9086967eb81b851dda to your computer and use it in GitHub Desktop.
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
user system total real | |
Forwardable 0.170000 0.000000 0.170000 ( 0.167711) | |
Send 0.110000 0.000000 0.110000 ( 0.106545) | |
Simple call 0.070000 0.000000 0.070000 ( 0.070068) |
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' | |
require 'forwardable' | |
class TestForwardable | |
extend Forwardable | |
def_delegators :@array, :size | |
def initialize | |
@array = (1..100).to_a | |
end | |
end | |
class TestMethod | |
def initialize | |
@array = (1..100).to_a | |
end | |
def size | |
@array.size | |
end | |
end | |
class TestSend | |
def initialize | |
@array = (1..100).to_a | |
end | |
def size | |
@array.send(:size) | |
end | |
end | |
forwardable = TestForwardable.new | |
sender = TestSend.new | |
method = TestMethod.new | |
Benchmark.bm do |x| | |
x.report("Forwardable") { 1_000_000.times { forwardable.size } } | |
x.report("Send") { 1_000_000.times { sender.size } } | |
x.report("Simple call") { 1_000_000.times { method.size } } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment