From: Notmy Realname Date: 2010-02-22T06:26:03+09:00 Subject: Re: Read efficiency? Robert Klemme wrote: > On 02/21/2010 09:08 AM, Notmy Realname wrote: >> I hate it when I put my foot in my mouth. After further testing, I'm >> almost entirely sure this is just due to overhead, not a problem with >> disk access. > > Good that you did not use your real name. ;-) > >> Who would have thought looping 11*2**20 times would incur a performance >> hit? > > The overhead of a simple method call is significant already: > > robert@fussel:~$ ruby19 -r benchmark < def f;end # function without effect > R1=11*1024*1024 > R2=R1/4096 > Benchmark.bmbm 20 do |r| > r.report("rare") { R2.times { f } } > r.report("often") { R1.times { f } } > end > XXX > > Rehearsal ------------------------------------------------------- > rare 0.000000 0.000000 0.000000 ( 0.000643) > often 2.620000 0.000000 2.620000 ( 2.663366) > ---------------------------------------------- total: 2.620000sec > > user system total real > rare 0.000000 0.000000 0.000000 ( 0.000643) > often 2.620000 0.000000 2.620000 ( 2.665057) > robert@fussel:~$ > > Kind regards > > robert I know, right? I'm embarrassed I use this username elsewhere. And I spent like an hour trying to figure this out. In my defense, I did do more or less exactly what you did and found the function call overhead to be significant, but not enough to account for the difference. Then I remembered that Ruby isn't just doing a disk read---it's also doing stuff like packaging the bytes it reads into a string. Once I accounted for *that*, the difference magically disappeared. Note to self: Ruby is not C. -- Posted via http://www.ruby-forum.com/.