https://github.com/jekyll/jekyll
Raw File
Tip revision: 6dfae84da2ad327aa3401cf6456c9b5fa307ec76 authored by Parker Moore on 18 April 2016, 21:00:25 UTC
Release :gem: 3.0.4
Tip revision: 6dfae84
proc-call-vs-yield
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