Created
October 15, 2019 16:29
-
-
Save tadman/ed6bf2f9e9b2bb68a8818cc52075495e to your computer and use it in GitHub Desktop.
Method call vs. send benchmark in Ruby
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' | |
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