I’ll add string concatenation to the next benchmarksuite.
Regards,
Dan
···
-----Original Message-----
From: Robert Feldt [mailto:feldt@ce.chalmers.se]
Sent: Friday, June 13, 2003 10:14 AM
To: ruby-talk@ruby-lang.org
Subject: Re: Hispeed String concat
On Fri, 13 Jun 2003, Dave Thomas wrote:
I don’t believe there’s a single fastest way.
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 changingresult = "" 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
For “Ruby Developer’s Guide” I did some measurements on this and join was
often significantly faster when there are many strings to concat. Also “<<”
was somewhat but not much faster than “+=” (for many strings, for fewer
string “+=” was sometimes faster). Performance measurement is hairy business
though and its hard to generalise…
Regards,
Robert Feldt