Class: Benchmark::IPS::Report

Inherits:
Object
  • Object
show all
Defined in:
lib/benchmark/ips/report.rb

Overview

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

Defined Under Namespace

Classes: Entry

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeReport

Instantiate the Report.



131
132
133
134
# File 'lib/benchmark/ips/report.rb', line 131

def initialize
  @entries = []
  @data = nil
end

Instance Attribute Details

#entriesArray<Report::Entry> (readonly)

Entry to represent each benchmarked code in Report.

Returns:



128
129
130
# File 'lib/benchmark/ips/report.rb', line 128

def entries
  @entries
end

Instance Method Details

#add_entry(label, microseconds, iters, stats, measurement_cycle) ⇒ Report::Entry

Add entry to report.

Parameters:

  • label (String)

    Entry label.

  • microseconds (Integer)

    Measured time in microsecond.

  • iters (Integer)

    Iterations.

  • stats (Object)

    Statistical results.

  • measurement_cycle (Integer)

    Number of cycles.

Returns:



143
144
145
146
147
148
# File 'lib/benchmark/ips/report.rb', line 143

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

#dataArray<Hash<Symbol,String|Float|Integer>] Array of hashes

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

Returns:

  • (Array<Hash<Symbol,String|Float|Integer>] Array of hashes)

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



159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/benchmark/ips/report.rb', line 159

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) ⇒ Object

Generate json from Report#data to given path.

Parameters:

  • path (String)

    path to generate json.



181
182
183
184
185
186
# File 'lib/benchmark/ips/report.rb', line 181

def generate_json(path)
  File.open path, "w" do |f|
    require "json"
    f.write JSON.pretty_generate(data)
  end
end

#run_comparisonObject

Run comparison of entries.



175
176
177
# File 'lib/benchmark/ips/report.rb', line 175

def run_comparison
  Benchmark.compare(*@entries)
end