Skip to content

Instantly share code, notes, and snippets.

@happyrobots
Created July 6, 2011 14:23
Show Gist options
  • Save happyrobots/1067344 to your computer and use it in GitHub Desktop.
Save happyrobots/1067344 to your computer and use it in GitHub Desktop.
Map is incredibly slow. Of course it's a little bit weird to let Ruby run 10M loop.
require 'benchmark'
MAX = 10_000_000
Benchmark.bm(3) do |b|
b.report("push") do
arr = []
MAX.times {|i| arr.push(i.to_s)}
end
b.report("map") do
arr = (0...MAX).map(&:to_s)
end
end
user system total real
push 24.460000 1.880000 26.340000 ( 26.850189)
map 36.910000 0.910000 37.820000 ( 39.286317)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment