Revision b6b8c0379fce5907c435fa305f5ac8ee99659de5 authored by Frank Taillandier on 06 July 2020, 21:09:01 UTC, committed by GitHub on 06 July 2020, 21:09:01 UTC
1 parent bbde471
Raw File
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