Report contains benchmarking entries. Perform operations like add new entry, run comparison between entries.
Instantiate the Report.
# File lib/benchmark/ips/report.rb, line 124 def initialize @entries = [] @data = nil end
Add entry to report. @param label [String] Entry label. @param microseconds [Integer] Measured time in microsecond. @param iters [Integer] Iterations. @param ips [Float] Average Iterations per second. @param ips_sd [Float] Standard deviation of iterations per second. @param measurement_cycle [Integer] Number of cycles. @return [Report::Entry] Last added entry.
# File lib/benchmark/ips/report.rb, line 137 def add_entry label, microseconds, iters, ips, ips_sd, measurement_cycle entry = Entry.new(label, microseconds, iters, ips, ips_sd, measurement_cycle) @entries.delete_if { |e| e.label == label } @entries << entry entry end
Entries data in array for generate json. Each entry is a hash, consists of:
name: Entry#label ips: Entry#ips stddev: Entry#ips_sd
@return [Array<Hash<Symbol,String|Float>] Array of hashes with :label, :ips, :stddev
# File lib/benchmark/ips/report.rb, line 150 def data @data ||= @entries.collect do |entry| { :name => entry.label, :ips => entry.ips, :stddev => entry.ips_sd } end end
Generate json from #data to given path. @param path [String] path to generate json.
# File lib/benchmark/ips/report.rb, line 167 def generate_json(path) File.open path, "w" do |f| require "json" f.write JSON.pretty_generate(data) end end
Run comparison of entries.
# File lib/benchmark/ips/report.rb, line 161 def run_comparison Benchmark.compare(*@entries) end