https://github.com/jekyll/jekyll
Raw File
Tip revision: 3874e124d7f41bf3f79b7a11c469c73f725cc28f authored by Ashwin Maroli on 20 January 2023, 18:09:01 UTC
Release :gem: v4.3.2
Tip revision: 3874e12
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