class Benchmark::IPS::Report

Report contains benchmarking entries. Perform operations like add new entry, run comparison between entries.

Attributes

entries[R]

Entry to represent each benchmarked code in Report. @return [Array<Report::Entry>] Entries in Report.

Public Class Methods

new() click to toggle source

Instantiate the Report.

# File lib/benchmark/ips/report.rb, line 124
def initialize
  @entries = []
  @data = nil
end

Public Instance Methods

add_entry(label, microseconds, iters, ips, ips_sd, measurement_cycle) click to toggle source

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
data() click to toggle source

Entries data in array for generate json. Each entry is a hash, consists of:

name:   Entry#label
ips:    Entry#ips
stddev: Entry#ips_sd
microseconds: Entry#microseconds
iterations:   Entry#iterations
cycles:       Entry#measurement_cycles

@return [Array<Hash<Symbol,String|Float|Integer>] Array of hashes

# File lib/benchmark/ips/report.rb, line 153
def data
  @data ||= @entries.collect do |entry|
    {
      :name => entry.label,
      :ips =>  entry.ips,
      :stddev => entry.ips_sd,
      :microseconds => entry.microseconds,
      :iterations => entry.iterations,
      :cycles => entry.measurement_cycle,
    }
  end
end
generate_json(path) click to toggle source

Generate json from #data to given path. @param path [String] path to generate json.

# File lib/benchmark/ips/report.rb, line 173
def generate_json(path)
  File.open path, "w" do |f|
    require "json"
    f.write JSON.pretty_generate(data)
  end
end
run_comparison() click to toggle source

Run comparison of entries.

# File lib/benchmark/ips/report.rb, line 167
def run_comparison
  Benchmark.compare(*@entries)
end