Created
July 6, 2011 14:23
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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