Last active
March 8, 2019 19:10
-
-
Save jjb/40496d0f74ee479079df867fb2f2070d to your computer and use it in GitHub Desktop.
Ruby String Interpolation vs. Concatenation performance benchmark
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
t = Time.now | |
a = [] | |
10_000_000.times do | |
a << "a" + " " + "b" | |
end | |
puts Time.now.to_f - t.to_f |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
t = Time.now | |
a = [] | |
10_000_000.times do | |
a << "#{"a"} #{"b"}" | |
end | |
puts Time.now.to_f - t.to_f |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
➔ 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