Skip to content

Instantly share code, notes, and snippets.

@jjb

jjb/concat.rb

Last active Mar 8, 2019
Embed
What would you like to do?
Ruby String Interpolation vs. Concatenation performance benchmark
t = Time.now
a = []
10_000_000.times do
a << "a" + " " + "b"
end
puts Time.now.to_f - t.to_f
t = Time.now
a = []
10_000_000.times do
a << "#{"a"} #{"b"}"
end
puts Time.now.to_f - t.to_f
➔ ruby interp.rb
1.5596427917480469
➔ ruby concat.rb
7.423596143722534
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.