Skip to content

Instantly share code, notes, and snippets.

@Koronen
Last active August 29, 2015 13:57
Show Gist options
  • Save Koronen/9639596 to your computer and use it in GitHub Desktop.
Save Koronen/9639596 to your computer and use it in GitHub Desktop.
require 'benchmark'
n = 2000000
Benchmark.bm do |x|
arr = 1.upto(1000).to_a
x.report('<<') do
1.upto(n) do |i|
arr << i
end
end
arr = 1.upto(1000).to_a
x.report('+ ') do
1.upto(n) do |i|
arr + [i]
end
end
end
user system total real
<< 0.350000 0.010000 0.360000 ( 0.370955)
+ 8.010000 0.010000 8.020000 ( 8.030394)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment