File: splat_vs_flatten.rb

package info (click to toggle)
yard 0.9.38-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,736 kB
  • sloc: ruby: 31,680; javascript: 7,658; makefile: 21
file content (13 lines) | stat: -rw-r--r-- 391 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
# frozen_string_literal: true
require "benchmark"

# To prove that flattening a small list is not significantly slower than
# calling *list (used to get around create_tag list issue)
$a = "FOO BAR BAZ"
def foo(*args) args.last.inspect end

TESTS = 10_000
Benchmark.bmbm do |x|
  x.report("splat") { TESTS.times { foo(*$a) } }
  x.report("flatten") { TESTS.times { foo(*[$a].flatten) } }
end