Skip to content

Instantly share code, notes, and snippets.

@ukstv
Created October 4, 2016 15:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ukstv/6db4ba04e8f9cb2c56641005dd188237 to your computer and use it in GitHub Desktop.
Save ukstv/6db4ba04e8f9cb2c56641005dd188237 to your computer and use it in GitHub Desktop.
Results of a splat call benchmark
require "benchmark"
iterations = 10_000_000
def splat(*args)
args.first
end
def nosplat(args)
args.first
end
Benchmark.bm do |bm|
bm.report("Using the splat operator") do
iterations.times do
splat(1)
splat([1, 2, 3, 4, 5, 6])
end
end
bm.report("Using sequence of params") do
iterations.times do
nosplat([1])
nosplat([1, 2, 3, 4, 5 ,6])
end
end
end
user system total real
Using the splat operator 4.930000 0.010000 4.940000 ( 4.950988)
Using sequence of params 4.130000 0.010000 4.140000 ( 4.148014)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment