class Benchmark::IPS::Job
def run_benchmark
def run_benchmark @list.each do |item| if hold? && @held_results && @held_results.key?(item.label) result = @held_results[item.label] create_report(item.label, result['measured_us'], result['iter'], result['avg_ips'], result['sd_ips'], result['cycles']) next end @suite.running item.label, @time if @suite @stdout.running item.label, @time if @stdout Timing.clean_env iter = 0 measurements_us = [] # Running this number of cycles should take around 100ms. cycles = @timing[item] target = Time.now + @time while Time.now < target before = Time.now item.call_times cycles after = Time.now # If for some reason the timing said this took no time (O_o) # then ignore the iteration entirely and start another. iter_us = time_us before, after next if iter_us <= 0.0 iter += cycles measurements_us << iter_us end final_time = Time.now measured_us = measurements_us.inject(0) { |a,i| a + i } all_ips = measurements_us.map { |time_us| iterations_per_sec cycles, time_us } avg_ips = Timing.mean(all_ips) sd_ips = Timing.stddev(all_ips, avg_ips).round rep = create_report(item.label, measured_us, iter, avg_ips, sd_ips, cycles) if (final_time - target).abs >= (@time.to_f * MAX_TIME_SKEW) rep.show_total_time! end @stdout.add_report rep, caller(1).first if @stdout @suite.add_report rep, caller(1).first if @suite if hold? && item != @list.last File.open @held_path, "a" do |f| require "json" f.write JSON.generate({ :item => item.label, :measured_us => measured_us, :iter => iter, :avg_ips => avg_ips, :sd_ips => sd_ips, :cycles => cycles }) f.write "\n" end return true end end if hold? && @full_report.entries.size == @list.size File.delete @held_path if File.exist?(@held_path) end false end