https://github.com/jekyll/jekyll
Raw File
Tip revision: e0d49e2c0188a77f40ed4359497b5c996681dbaa authored by Parker Moore on 01 July 2017, 02:14:44 UTC
Release :gem: 3.4.5
Tip revision: e0d49e2
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