Skip to content

Instantly share code, notes, and snippets.

@Erol
Last active December 17, 2015 13:38
Show Gist options
  • Save Erol/5618098 to your computer and use it in GitHub Desktop.
Save Erol/5618098 to your computer and use it in GitHub Desktop.
Benchmark: String#+ vs String#<<
require 'benchmark'
s = ""
t = ""
n = 100_000
Benchmark.bm(10) do |bm|
bm.report('String#+') { n.times { s += "A" } }
bm.report('String#<<') { n.times { t << "A" } }
end
user system total real
String#+ 1.450000 0.840000 2.290000 ( 2.289673)
String#<< 0.010000 0.000000 0.010000 ( 0.016658)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment