From: Robert Dober Date: 2006-03-29T20:52:22+09:00 Subject: Re: strings and ruby style? ------=_Part_543_30243763.1143633139573 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline And the winner is.... -----------------------------------8<-------------------------------------- 626/126 > cat stringperf.rb ; ruby stringperf.rb #!/usr/bin/env ruby require 'benchmark' n =3D 10000 Benchmark.bm do |bm| bm.report "String#+ " do n.times do actual =3D '' %w{alpha beta gamma soup}.each do |x| actual =3D actual + x end end end # do bm.report "Interpolation" do n.times do %w{alpha beta gamma soup}.each do |x| actual =3D "#{actual}#{x}" end end end # do bm.report "Format " do n.times do %w{alpha beta gamma soup}.each do |x| actual =3D "%s%s" % [actual, x] end end end end # do user system total real String#+ 0.090000 0.000000 0.090000 ( 0.109451) Interpolation 0.150000 0.000000 0.150000 ( 0.153926) Format 0.210000 0.000000 0.210000 ( 0.226805) -----------------------------------8<-------------------------------------- Robert -- Deux choses sont infinies : l'univers et la b=EAtise humaine ; en ce qui concerne l'univers, je n'en ai pas acquis la certitude absolue. - Albert Einstein ------=_Part_543_30243763.1143633139573--