From: nobu.nokada@... Date: 2002-12-11T15:18:05+09:00 Subject: Re: replacing chars in string Hi, At Wed, 11 Dec 2002 14:58:28 +0900, why the lucky stiff wrote: > n = 1000 > str = "count=(a+b); if(a<=b) d[i]=10;f(a,b)" > test = nil > bm do |x| > x.report( "chained gsubs:" ) do > n.times do > test = str.gsub(/,/,' , ').gsub(/\(/,' ( ').gsub(/\)/,' ) ').gsub(/([^<>])=/,'\1 = ').gsub(/;/,";\n") > end > # puts > # p test > end x.report( "chained gsubs 2:" ) do n.times do test = str.gsub(/[,()]/,' \& ').gsub(/([^<>])=/,'\1 = ').gsub(/;/,";\n") end # puts # p test end With 10,000 iterations: user system total real chained gsubs: 2.270000 0.020000 2.290000 ( 2.306303) chained gsubs 2: 2.030000 0.040000 2.070000 ( 2.066607) grouped gsub: 5.570000 0.060000 5.630000 ( 5.758734) gsub and case: 3.720000 0.070000 3.790000 ( 3.950212) -- Nobu Nakada