------ extPart_000_0118_01C5B93C.36D7B610 Content-Type: text/plain; charset so-8859-1" Content-Transfer-Encoding: 7bit Hugh Sasse wrote: > On Wed, 14 Sep 2005, Robert Klemme wrote: > >> Hugh Sasse wrote: >>>> see an associated block, it doesn't handle the cleanup for you. >>> >>> Yes, that's right. I wonder if it is worth the price in garbage >>> collection to explicitly close in this case? Probably not given >>> maintenance costs. >> >> The closing isn't that costly. > > The closing would allow you to avoid that block with the |io| in it. > That cost, the cost of the object, is what I meant. What object exactly do you mean? The IO instance is there anyway so you probably are referring to the overhead incurred by the block. I don't think that this is significant. 14:50:33 [ruby]: ruby block-overhead.rb 1000000 user system total real block 3.563000 0.016000 3.579000 ( 3.569000) no block 1.859000 0.000000 1.859000 ( 1.867000) That's 1.704 seconds so 1.7 micro seconds per invocation. Not really much compared to the overhead of opening the file and all the other work. Kind regards robert ------ extPart_000_0118_01C5B93C.36D7B610 Content-Type: application/octet-stream; namelock-overhead.rb" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filenamelock-overhead.rb" require 'benchmark' REP = 1_000_000 p REP def foo if block_given? yield 0 else 0 end end Benchmark.bm(20) do |bb| bb.report "block" do EP.times { foo() {|i| i + 1 } } end bb.report "no block" do EP.times { foo() + 1 } end end ----- extPart_000_0118_01C5B93C.36D7B610--