Hispeed String concat

these speed quirks are interesting… do we have something similar on wiki?

···

-----Original Message-----
From: Dominik Werder [mailto:dwerder@gmx.net]
Sent: Monday, June 16, 2003 4:18 PM
To: ruby-talk@ruby-lang.org
Subject: Re: Hispeed String concat

I found also something interesting:

“Pre#{i.to_s}Post” seams to me cheaper than ‘Pre’<<i.to_s<<‘Post’

although ruby has to parse the double quoted string?

bye!
Dominik

Often ‘<<’ is fast, but not always.

In one application, where I was generating a CVS file from
a largish
SQL
result set, I made the program over 100 times faster by changing

result = “”
for r in results
csv_string = to_csv(r)
result << csv_string
end

to

result =
for r in results
csv_string = to_csv(r)
result << csv_string
end
result = result.join