Skip to content

Instantly share code, notes, and snippets.

@os6sense
Created February 17, 2014 11:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save os6sense/9049187 to your computer and use it in GitHub Desktop.
Save os6sense/9049187 to your computer and use it in GitHub Desktop.
require 'benchmark'
Benchmark.bm(20) do |x|
x.report ('<<') do
out = ""
100_000.times do
one = 'one'
two = 'two'
three = 'three'
out << "#{one}" << "#{two}" << "#{three}"
end
end
x.report ('concat') do
out = ""
100_000.times do
one = 'one'
two = 'two'
three = 'three'
out.concat(one.concat(two).concat(three))
end
end
x.report('+') do
out = ""
100_000.times do
one = 'one'
two = 'two'
three = 'three'
out += one + two + three
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment