From: Robert Klemme Date: 2009-02-27T23:49:32+09:00 Subject: Re: Array performance question --000325575702084c5f0463e7973b Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 2009/2/27 Jim Menard : > Here's a real Array performance mystery. I can't help my friend figure > this one out. He writes, > > =3D=3D=3D=3D=3D=3D=3D=3D > > Is there a known bug in Ruby array performance? =A0I spent a lot of time > yesterday boiling down the following example > > > http://blogs.codehaus.org/people/geir/archives/001768_baffled_with_ruby.h= tml > > only because I still can't believe I'm not doing something incredibly > stupid. =A0(I'm a newbie, "Reluctant Rubyist") > > =A0I'm just not used to arrays behaving this way :) =A0Anyone have any > insight? > > =3D=3D=3D=3D=3D=3D=3D=3D > > He'd love a response in his blog, but with permission I'll copy > answers here over there. He's not a regular ruby-talk reader...yet. Slightly modified test (attached): 15:44:06 Temp$ ruby bm.rb bm; ruby bm.rb bmbm; ruby19 bm.rb bm; ruby19 bm.rb bmbm 1.8.7 user system total real size =3D 10000 10000 0.125000 0.000000 0.125000 ( 0.11400= 0) size =3D 100000 100000 0.859000 0.000000 0.859000 ( 0.86300= 0) size =3D 1000000 1000000 24.969000 0.000000 24.969000 ( 24.96100= 0) 1.8.7 Rehearsal ----------------------------------------------------------------- size =3D 10000 10000 24.235000 0.032000 24.267000 ( 24.30800= 0) size =3D 100000 100000 18.078000 0.000000 18.078000 ( 18.15063= 0) size =3D 1000000 1000000 14.297000 0.000000 14.297000 ( 14.28900= 0) ------------------------------------------------------- total: 56.642000sec user system total real size =3D 10000 10000 12.031000 0.000000 12.031000 ( 12.03900= 0) size =3D 100000 100000 10.250000 0.000000 10.250000 ( 10.29095= 0) size =3D 1000000 1000000 8.985000 0.000000 8.985000 ( 8.98900= 0) 1.9.1 user system total real size =3D 10000 10000 0.016000 0.000000 0.016000 ( 0.02700= 0) size =3D 100000 100000 0.031000 0.000000 0.031000 ( 0.02800= 0) size =3D 1000000 1000000 0.047000 0.000000 0.047000 ( 0.04300= 0) 1.9.1 Rehearsal ----------------------------------------------------------------- size =3D 10000 10000 0.032000 0.000000 0.032000 ( 0.04300= 0) size =3D 100000 100000 0.032000 0.000000 0.032000 ( 0.04300= 0) size =3D 1000000 1000000 0.031000 0.000000 0.031000 ( 0.04300= 0) -------------------------------------------------------- total: 0.095000sec user system total real size =3D 10000 10000 0.031000 0.000000 0.031000 ( 0.03900= 0) size =3D 100000 100000 0.047000 0.000000 0.047000 ( 0.04300= 0) size =3D 1000000 1000000 0.032000 0.000000 0.032000 ( 0.04300= 0) Strange that the rehearsal has this dramatic effect. Normally it should simply execute the block twice to warm up the system. Kind regards robert --=20 remember.guy do |as, often| as.you_can - without end --000325575702084c5f0463e7973b Content-Type: application/octet-stream; name="bm.rb" Content-Disposition: attachment; filename="bm.rb" Content-Transfer-Encoding: base64 X-Attachment-Id: f_frozcw6n0 IyEvdXNyL2Jpbi9lbnYgcnVieQoKcHV0cyBSVUJZX1ZFUlNJT04KCnJlcXVpcmUgJ2JlbmNobWFy aycKCmNsYXNzIEJ1ZmZlckNvbnRhaW5lcgoKICBkZWYgaW5pdGlhbGl6ZShpbml0aWFsX2RhdGEp CiAgICBAYnVmPWluaXRpYWxfZGF0YQogIGVuZAoKICBkZWYgcHV0X2FycmF5KGFycmF5KQogICAg QGJ1ZlswLCBhcnJheS5sZW5ndGhdID0gYXJyYXkKICBlbmQKZW5kCgptZXRoID0gQVJHVi5zaGlm dCB8fCAiYm0iCgpCZW5jaG1hcmsuc2VuZCBtZXRoLCAzMCBkbyB8eHwKICBzaXplID0gMTAwMAog IHRoZWFycmF5ID0gWzAsIDEsIDIsIDMsIDRdCgogIGZvciBpIGluICgxLi4zKQogICAgc2l6ZSAq PSAxMAogICAgYSA9IEFycmF5Lm5ldyhzaXplKQoKICAgIHgucmVwb3J0ICJzaXplID0gI3tzaXpl fSAje2EubGVuZ3RofSIgZG8KICAgICAgMTBfMDAwLnRpbWVzIGRvCiAgICAgICAgYnVmID0gQnVm ZmVyQ29udGFpbmVyLm5ldyhhKQogICAgICAgIGJ1Zi5wdXRfYXJyYXkodGhlYXJyYXkpCiAgICAg IGVuZAogICAgZW5kCiAgZW5kCmVuZAoK --000325575702084c5f0463e7973b--