https://github.com/jekyll/jekyll
Raw File
Tip revision: c50821b69c939486a08ca85dd28aee8b55899d1a authored by Parker Moore on 08 April 2021, 14:50:38 UTC
Release :gem: 3.9.1
Tip revision: c50821b
proc-call-vs-yield
#!/usr/bin/env ruby
require 'benchmark/ips'

def fast
  yield
end

def slow(&block)
  block.call
end

Benchmark.ips do |x|
  x.report('yield') { fast { (0..9).to_a } }
  x.report('block.call') { slow { (0..9).to_a } }
end
back to top