Skip to content

Instantly share code, notes, and snippets.

@Erol
Last active December 17, 2015 13:38
Show Gist options
  • Save Erol/5618137 to your computer and use it in GitHub Desktop.
Save Erol/5618137 to your computer and use it in GitHub Desktop.
Benchmark: String Interpolation vs Concatenation
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
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