From: Mark Hubbart Date: 2004-04-07T12:00:16+09:00 Subject: Re: Bug in sub? On Apr 6, 2004, at 3:29 PM, Robert Feldt wrote: > I added a note to my code review checklist to "always" use the block > form... ;) only one problem with that: mark@imac% cat test.rb require 'profile' def gsub_block_test(string, pat, str) 10000.times{ string.gsub(pat){str} } end def gsub_arg_test(string, pat, str) 10000.times{ string.gsub(pat,str) } end gsub_arg_test("testing this out", /[aeiou]/, ".") gsub_block_test("testing this out", /[aeiou]/, ".") mark@imac% ruby test.rb % cumulative self self total time seconds seconds calls ms/call ms/call name 54.97 13.65 13.65 20000 0.68 0.68 String#gsub 44.95 24.81 11.16 2 5580.00 12405.00 Integer#times 0.48 24.93 0.12 1 120.00 120.00 Profiler__.start_profile 0.00 24.93 0.00 2 0.00 0.00 Module#method_added 0.00 24.93 0.00 1 0.00 16550.00 Object#gsub_block_test 0.00 24.93 0.00 1 0.00 8260.00 Object#gsub_arg_test 0.00 24.93 0.00 1 0.00 24830.00 #toplevel the block version of this same test takes twice as long :) --Mark