Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
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
This paste will be private.
From the Design Piracy series on my blog: