Last active
December 17, 2015 13:38
-
-
Save Erol/5618137 to your computer and use it in GitHub Desktop.
Benchmark: String Interpolation vs Concatenation
This file contains 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
require 'benchmark' | |
n = 100_000 | |
Benchmark.bm(10) do |bm| | |
bm.report('interpolation') { n.times { "#{ 1 }/#{ 2 }" } } | |
bm.report('concatenation') { n.times { 1.to_s + '/' + 2.to_s } } | |
end |
This file contains 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
user system total real | |
interpolation 0.050000 0.000000 0.050000 ( 0.045237) | |
concatenation 0.060000 0.000000 0.060000 ( 0.058181) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment