From: Vincent Fourmond Date: 2007-01-10T05:53:59+09:00 Subject: Re: String performance George Palmer wrote: > Guys a quick performance question - Is either one of the following more > efficient than the other? I'm guessing they're in this order: > > 'a' + x + 'b' > "a" + x + "b" > "a#{x}b" Exactly the opposite: 21:52 vincent@tanyaivinco ~/Prog/Ruby ruby rt_7.rb user system total real 0.010000 0.000000 0.010000 ( 0.009087) 0.010000 0.000000 0.010000 ( 0.008774) 0.000000 0.000000 0.000000 ( 0.004621) rt_7.rb is require 'benchmark' n = 5000 c = "stuff" Benchmark.bm do |x| x.report { n.times {'a' + c + 'b'}} x.report { n.times {"a" + c + "b"}} x.report { n.times {"a#{c}b"}} end If you're looking for a performance question, Benchmark is nearly always your answer. Vince -- Vincent Fourmond, PhD student http://vincent.fourmond.neuf.fr/