Skip to content

Instantly share code, notes, and snippets.

@tadman
Created October 15, 2019 16:29
Show Gist options
  • Save tadman/ed6bf2f9e9b2bb68a8818cc52075495e to your computer and use it in GitHub Desktop.
Save tadman/ed6bf2f9e9b2bb68a8818cc52075495e to your computer and use it in GitHub Desktop.
Method call vs. send benchmark in Ruby
require 'benchmark'
Benchmark.bm do |bm|
repeat = 10000000
bm.report('send') { repeat.times { 5.send(:>, 2) } }
bm.report('method.call') { repeat.times { 5.method(:>).call(2) } }
end
# user system total real
# send 0.640115 0.000992 0.641107 ( 0.642627)
# method.call 2.629482 0.007149 2.636631 ( 2.644439)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment