require 'benchmark'

(ARGV[0] || 1).to_i.times do
Benchmark.bm(30) do |bm|
bm.report("control") { 1_000_000.times { a = ''; a = 'hello'; a = 'hello'; a = 'hello' } }
bm.report("string concat") { 1_000_000.times { a = ''; a.concat('hello'); a.concat('hello'); a.concat('hello') } }
bm.report("string concat") { 1_000.times { @a = ''; 1000.times { @a.concat(rand(5000).to_s); @a.concat(rand(5000).to_s); @a.concat(rand(5000).to_s) } } }
end
end