Issue #5127 has been updated by Tomoyuki Chikanaga.


Linux(Ubuntu 10.4 gcc 4.4.3) ????試?????????????????????????????????????????????????????????1.9.3 ?????? trunk ???????????

$ ruby-1.9.2 bm_array.rb
                            user     system      total        real
Array.new               2.340000   0.070000   2.410000 (  2.427617)
Array#[]= with Array   23.850000   1.220000  25.070000 ( 25.506229)

$ ruby-trunk bm_array.rb
                             user     system      total        real
Array.new                2.200000   0.930000   3.130000 (  3.161638)
Array#[]= with Array    44.950000   1.250000  46.200000 ( 46.584050)

???????????以??????????? GC ???????????????????????????????????????????????????????????????????????????????????????????????????????? ObjectSpace.each_object ????????????????????????????????????????????????主?? GC ??影??????????????????????????????????????????

$ cat bm_array.rb
require 'benchmark'

Benchmark.bm(22) do |x|
  GC.disable
  x.report "Array.new" do
    1_000_000.times do
      Array.new(100)
    end
  end
  puts "objects count = #{ ObjectSpace.each_object{} }"
  GC.enable
  GC.start
  GC.disable
  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
  puts "objects count = #{ ObjectSpace.each_object{} }"
end

$ ruby-1.9.2 bm_array.rb
                            user     system      total        real
Array.new               1.470000   1.220000   2.690000 (  2.705700)
objects count = 1007204
Array#[]= with Array    1.910000   0.030000   1.940000 (  2.055783)
objects count = 1003992

$ ruby-trunk bm_array.rb
                             user     system      total        real
Array.new                1.510000   1.230000   2.740000 (  2.753933)
objects count = 1005182
Array#[]= with Array     1.940000   0.010000   1.950000 (  1.977659)
objects count = 1002551
----------------------------------------
Bug #5127:  ruby 1.9.3 prev1  ??? Array#[]=( Array.new ) ???1.9.2??????2?????????
http://redmine.ruby-lang.org/issues/5127

Author: Anonymous
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 1.9.3
ruby -v: -


 Array????????????? Array#[]= ??設???????????????
 ruby 1.9.3 prev1 ??? 1.9.2 p290 ???????????2??????????????????????????????
 ???????????????????????
 
 (????籡???????????????訳?????????????????????????????????)
 
 ----
 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
 ----
 
 ????????????????????????????????????以???????????????????????????
 $ 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)
 
 
 使?????????????????
 - OS      : Mac OS X 10.7
 - CPU     : Intel Core i5
 - Memory  : 4GB
 - compiler: gcc 4.2.1
 ???????
 
 
 以???????????????????????????????????????


-- 
http://redmine.ruby-lang.org