# File lib/railsbench/perf_utils.rb, line 130
def perf_run(script, iterations, options, raw_data_file)
  perf_runs = (ENV['RAILS_PERF_RUNS'] ||= "3").to_i

  disable_gc_stats
  set_gc_variables([iterations, options])

  perf_options = "#{iterations} #{options}"
  null = (RUBY_PLATFORM =~ /win32/i) ? 'nul' : '/dev/null'

  perf_cmd = "#{ruby} #{RAILSBENCH_BINDIR}/perf_bench #{perf_options}"
  print_cmd = "#{ruby} #{RAILSBENCH_BINDIR}/perf_times #{raw_data_file}"

  puts "benchmarking #{perf_runs} runs with options #{perf_options}"

  File.open(raw_data_file, "w"){ |f| f.puts perf_cmd }
  perf_runs.times do
    system("#{perf_cmd} >#{null}") || die("#{script}: #{perf_cmd} returned #{$?}")
  end
  File.open(raw_data_file, "a" ){|f| f.puts }

  unset_gc_variables
  system(print_cmd) || die("#{script}: #{print_cmd} returned #{$?}")
end