All pastes #473324 Raw Edit

string benchmark

public ruby v1 · immutable
·published 2007-05-06 05:16 UTC
rendered paste body
require 'benchmark'N = 10_000Benchmark.bm(20) do |x|  x.report('<<') do    N.times do |i|      one = 'one' * i      two = 'two' * i      three = 'three' * i      y = one << two << three    end  end  x.report('+') do    N.times do |i|      one = 'one' * i      two = 'two' * i      three = 'three' * i      y = one + two + three    end  end  x.report('#{one}#{two}#{three}') do    N.times do |i|      one = 'one' * i      two = 'two' * i      three = 'three' * i      y = "#{one}#{two}#{three}"    end  end  x.report('one#{two}#{three}') do    N.times do |i|      two = 'two' * i      three = 'three' * i      y = "one#{two}#{three}"    end  end  x.report('onetwo#{three}') do    N.times do |i|      three = 'three' * i      y = "onetwo#{three}"    end  endend