Skip to content

Instantly share code, notes, and snippets.

@lulalala
Created October 16, 2013 08:48
Show Gist options
  • Select an option

  • Save lulalala/7004688 to your computer and use it in GitHub Desktop.

Select an option

Save lulalala/7004688 to your computer and use it in GitHub Desktop.
Using splat to accept large array is slow.
require 'benchmark'
iterations = 100_000
def a(*args)
args.size
end
def b(args)
args.size
end
big_array = (1..100).to_a
Benchmark.bmbm do |bm|
bm.report('use splat') do
iterations.times do
a(*big_array)
end
end
bm.report('pass array') do
iterations.times do
b(big_array)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment