Forum: Ruby Re: String performance

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
825738339f48c5b8b2a72c02caf3d91c?d=identicon&s=25 Gavin Kistner (Guest)
on 2007-01-09 22:02
(Received via mailing list)
From: George Palmer
> 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"

Despite the intuition, I've never been able to prove that "foo" vs.
'foo' is measurably slower or faster.

String interpolation is, however, faster than either of the above. (I'm
not sure why, but my guess is that it has to do with how many
intermediary strings are created.)
This topic is locked and can not be replied to.