# # Tests the overhead of literal versus processed String object constructors. # require 'rubygems' require './better-benchmark' ENV['R_HOME']='/usr/local/lib/R' ITERATIONS = 10 INNER_ITER = 200000 STRING = 'A' puts "Testing against Ruby #{RUBY_VERSION}" puts '' puts "Building String object constructor test cases..." puts '' test_literal = "String.new('#{STRING}')\n" test_process = "String.new(\"#{STRING}\")\n" (0..9).each do 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 '' end