On Thu, Mar 5, 2009 at 2:00 PM, Gennady Bystritsky <Gennady.Bystritsky / quest.com> wrote: >> -----Original Message----- >> From: Leo [mailto:minilith / gmail.com] >> Sent: Wednesday, March 04, 2009 9:53 PM >> >> > string.scan(%r{.{1,80}}).map { |_chunk| >> > _chunk + '<br />' >> > } >> >> Isn't that pretty much the same as: >> >> string.gsub(%r{.{1,80}}, "\\0<br />") > > [...] > The latter may be faster, though. Doesn't appear to be. http://gist.github.com/74249 I threw in a primitive insert loop for comparison and was a little surprised to find it considerably slower than both the others. ruby 1.9.1p0 (2009-01-30 revision 21907) [i386-darwin8.11.1] user system total real with_scan 0.750000 0.040000 0.790000 ( 0.851104) with_gsub 0.840000 0.060000 0.900000 ( 0.950050) with_insert 2.000000 0.050000 2.050000 ( 2.210962) Solidarity, lasitha.