Skip to content

Instantly share code, notes, and snippets.

@zzak
Created December 28, 2016 03:16
Show Gist options
  • Save zzak/31411b17ae1e2db84eb44525170476ae to your computer and use it in GitHub Desktop.
Save zzak/31411b17ae1e2db84eb44525170476ae to your computer and use it in GitHub Desktop.
Warming up --------------------------------------
Forwardable 148.719k i/100ms
Send 334.975k i/100ms
Simple call 380.722k i/100ms
Calculating -------------------------------------
Forwardable 1.999M (± 5.0%) i/s - 10.113M in 5.073999s
Send 7.768M (± 5.4%) i/s - 38.857M in 5.018102s
Simple call 10.120M (± 6.8%) i/s - 50.636M in 5.027285s
require 'benchmark/ips'
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.ips do |x|
x.report("Forwardable") { forwardable.size }
x.report("Send") { sender.size }
x.report("Simple call") { method.size }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment