Skip to content

Instantly share code, notes, and snippets.

@jqr
Created June 19, 2009 23:59
Show Gist options
  • Save jqr/132958 to your computer and use it in GitHub Desktop.
Save jqr/132958 to your computer and use it in GitHub Desktop.
require 'benchmark'
count = 10_000_000
Benchmark.bm(10) do |bm|
bm.report('control') { count.times { [1,2,3,4,5,6] } }
bm.report('splat') { count.times { [1,2,3, *[4,5,6]] } }
bm.report('plus') { count.times { [1,2,3] + [4,5,6] } }
bm.report('flatten') { count.times { [1,2,3, [4,5,6]].flatten } }
end
# user system total real
# control 4.550000 0.030000 4.580000 ( 4.781043)
# splat 9.100000 0.060000 9.160000 ( 9.354983)
# plus 10.130000 0.070000 10.200000 ( 10.392451)
# flatten 31.850000 0.210000 32.060000 ( 32.804879)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment