File: proc-call-vs-yield

package info (click to toggle)
jekyll 4.3.4%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,356 kB
  • sloc: ruby: 16,765; javascript: 1,455; sh: 214; xml: 29; makefile: 9
file content (15 lines) | stat: -rwxr-xr-x 222 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/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