Skip to content

Instantly share code, notes, and snippets.

@avgerin0s
Created April 13, 2015 09:37
Show Gist options
  • Save avgerin0s/85ef313f1e7014ead608 to your computer and use it in GitHub Desktop.
Save avgerin0s/85ef313f1e7014ead608 to your computer and use it in GitHub Desktop.
Splat operator benchmarking
user system total real
Using the splat operator 8.050000 0.160000 8.210000 ( 8.235298)
Using sequence of params 5.300000 0.170000 5.470000 ( 5.466839)
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin14.0]
require "benchmark"
iterations = 10_000_000
Benchmark.bm do |bm|
bm.report("Using the splat operator") do
iterations.times do
a = Array.new
a.unshift(*[1, 2, 3, 4, 5, 6])
end
end
bm.report("Using sequence of params") do
iterations.times do
a = Array.new
a.unshift(1, 2, 3, 4, 5 ,6)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment