# # Tests the overhead of literal versus processed String object constructors. Each # subsequent test increases the size of the constructor's initialization # value. # require 'rubygems' require './better-benchmark' ENV['R_HOME']='/usr/local/lib/R' ITERATIONS = 10 INNER_ITER = 200000 STRING = 'A' STEP = 100 MAX = 1000 puts "Testing against Ruby #{RUBY_VERSION}" puts '' i = 1 while 1 puts "Building test cases of #{i}-byte initialized String object constructors..." test_literal = "String.new('#{STRING*i}')\n" test_process = "String.new(\"#{STRING*i}\")\n" puts "Testing #{ITERATIONS} passes of #{INNER_ITER} iterations for literal (Set 1) versus processed (Set 2) String object constructors" result = Benchmark.compare_realtime( :iterations => ITERATIONS, :inner_iterations => INNER_ITER, :verbose => true ) {|iteration| eval(test_literal) }.with {|iteration| eval(test_process) } Benchmark.report_on(result) puts '' break if i >= MAX i == 1 ? i += (STEP - 1) : i += STEP end