https://github.com/jekyll/jekyll
Raw File
Tip revision: 9c2c01bb7a6e6c2e6711dcdb14f968dee4aaac2a authored by Ashwin Maroli on 20 October 2022, 16:02:59 UTC
Release :gem: v4.3.0
Tip revision: 9c2c01b
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