Skip to content

Instantly share code, notes, and snippets.

@jjb
Last active March 8, 2019 19:10
Show Gist options
  • Save jjb/40496d0f74ee479079df867fb2f2070d to your computer and use it in GitHub Desktop.
Save jjb/40496d0f74ee479079df867fb2f2070d to your computer and use it in GitHub Desktop.
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