# 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 145
    def initialize
      @entries = []
      @data = nil
    end

### Public Instance Methods

add_entry(label, microseconds, iters, stats, 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 stats [Object] Statistical results. @param measurement_cycle [Integer] Number of cycles. @return [Report::Entry] Last added entry.

    # File lib/benchmark/ips/report.rb, line 157
    def add_entry label, microseconds, iters, stats, measurement_cycle
      entry = Entry.new(label, microseconds, iters, stats, 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 173
    def data
      @data ||= @entries.collect do |entry|
        {
          :name => entry.label,
          :central_tendency =>  entry.stats.central_tendency,
          :ips =>  entry.stats.central_tendency, # for backwards compatibility
          :error => entry.stats.error,
          :stddev => entry.stats.error, # for backwards compatibility
          :microseconds => entry.microseconds,
          :iterations => entry.iterations,
          :cycles => entry.measurement_cycle,
        }
      end
    end

generate_json(path) click to toggle source

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

    # File lib/benchmark/ips/report.rb, line 195
    def generate_json(path)
      require "json"
      if path.respond_to?(:write) # STDOUT
        path.write JSON.pretty_generate(data)
      else
        File.open path, "w" do |f|
          f.write JSON.pretty_generate(data)
        end
      end
    end

run_comparison(order) click to toggle source

Run comparison of entries.

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