Created
May 16, 2019 21:45
-
-
Save XrXr/0e81775c2c430a73588b381fdd2fc47d to your computer and use it in GitHub Desktop.
Block-pass benchmark
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 'bundler/inline' | |
require 'benchmark/ips' | |
N = 10_000 | |
def without | |
yield | |
end | |
def with_dot_call(&block) | |
block.call | |
end | |
def with_but_yield(&block) | |
yield | |
end | |
Benchmark.ips do |x| | |
x.report("call without & argument") do | |
N.times do | |
without {} | |
end | |
end | |
x.report("call with explicit & argument and .call") do | |
N.times do | |
with_dot_call {} | |
end | |
end | |
x.report("call with explicit & argument and yield") do | |
N.times do | |
with_but_yield {} | |
end | |
end | |
x.compare! | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment