# Ruby 1.9.3 prev1 で Array#[]=( Array.new ) が1.9.2より2倍遅い

Array\$B%*%V%8%’%/%H\$r(B Array#[]= \$B\$G@_Dj\$9\$k>l9g\$K!"(B
ruby 1.9.3 prev1 \$B\$,(B 1.9.2 p290
\$B\$HHf3S\$7\$F(B2\$BG\$[\$ICY\$/\$J\$C\$F\$\$\$k\$h\$&\$J\$N\$G(B
\$B\$4Js9p\$\$\$?\$7\$^\$9!#(B

(\$B4{CN\$N8=>]\$G\$"\$l\$P!"?=\$7Lu\$"\$j\$^\$;\$s\$,%9%k!<\$7\$F\$/\$@\$5\$\$(B)

require ‘benchmark’

Benchmark.bm(22) do |x|
x.report “Array.new” do
1_000_000.times do
Array.new(100)
end
end

## x.report “Array#[]= with Array” do a = Array.new(1_000_000) 1_000_000.times do |i| a[i] = Array.new(100) end end end

\$B>e5-\$N%3!<%I\$r<B9T\$7\$?>l9g\$K!";d\$N4D6-\$G\$O0J2<\$N\$h\$&\$J7k2L\$H\$J\$j\$^\$9!#(B
\$ ruby19 -v bm_array.rb
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin11.0.0]
user system total real
Array.new 0.600000 0.140000 0.740000 ( 0.740639)
Array#[]= with Array 8.590000 0.300000 8.890000 ( 8.874507)

\$ ruby -v bm_array.rb
ruby 1.9.3dev (2011-07-31 revision 32789) [x86_64-darwin11.0.0]
user system total real
Array.new 0.670000 0.160000 0.830000 ( 0.826589)
Array#[]= with Array 16.160000 0.280000 16.440000 ( 16.597618)

\$B;HMQ\$7\$F\$\$\$k4D6-\$O(B

• OS : Mac OS X 10.7
• CPU : Intel Core i5
• Memory : 4GB
• compiler: gcc 4.2.1
\$B\$G\$9!#(B

\$B0J>e!"\$h\$m\$7\$/\$*4j\$\$\$\$\$?\$7\$^\$9!#(B