Skip to content

Instantly share code, notes, and snippets.

@karloscodes
Last active July 9, 2019 13:14
Show Gist options
  • Save karloscodes/edb9292b6d3f9eaa46fa9d83c5ecc73a to your computer and use it in GitHub Desktop.
Save karloscodes/edb9292b6d3f9eaa46fa9d83c5ecc73a to your computer and use it in GitHub Desktop.
Ruby inmutable array concatenation. A prove benchmark.
# ruby --version
# ruby 2.6.3p62
require 'benchmark'
def without_splat(a, b, c); end
def with_splat(*a); end
Benchmark.bm do |x|
x.report do
(1..100_000).each do |_i|
without_splat(1, 2, 3)
end
end
end
# user system total real
# 0.006128 0.000000 0.006128 ( 0.006139)
Benchmark.bm do |x|
x.report do
(1..100_000).each do |_i|
with_splat(1, 2, 3)
end
end
end
# user system total real
# 0.015717 0.000000 0.015717 ( 0.015867)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment