From: Jim Freeze Date: 2002-03-30T00:52:34+09:00 Subject: Re: optimization questions On Sat, Mar 30, 2002 at 12:08:56AM +0900, Yukihiro Matsumoto wrote: > Hi, > > In message "optimization questions" > on 02/03/29, George Moschovitis writes: > > |a. which is faster ? > | > |1. a = 'this is a string' > |or > |2. b = "this is a string" ? > > Same. > > |b. which is faster ? > | > |1. a = 'value1 = ' + value1 + ' value2 = ' + value2 > |or > |2. b = 'value1 = #{value1} value2 = #{value2}' ? > > They are almost same. > Hmm. I thought that << used to be fastest. Maybe only if I let s grow continuously. time ruby s.rb 7.89u 0.02s 0:07.94 99.6% cat s.rb v = "fred" 500000.times { s = "" s << "text" << v } time ruby s.rb 4.60u 0.02s 0:04.63 99.7% cat s.rb s = "" v = "fred" 500000.times { s = "text" + v } time ruby s.rb 3.78u 0.02s 0:03.84 98.9% cat s.rb s = "" v = "fred" 500000.times { s = "text#{v}" } -- Jim Freeze atto: 1e-18 = one quintillionth parsec: 3.258 light-years: 3.258 * 186000 * 364 * 24 * 3600 * 5280 * 12 attoparsec: atto * parsec =~ 1.20 inch My height: 62 inches / 1.2 = 51.7 attoparsecs ~