Re: String performance

From: George P.

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 forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs