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.



125
126
127
128
# File 'lib/benchmark/ips/report.rb', line 125

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

Instance Attribute Details

#entriesArray<Report::Entry> (readonly)

Entry to represent each benchmarked code in Report.

Returns:



122
123
124
# File 'lib/benchmark/ips/report.rb', line 122

def entries
  @entries
end

Instance Method Details

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

Add entry to report.

Parameters:

  • label (String)

    Entry label.

  • microseconds (Integer)

    Measured time in microsecond.

  • iters (Integer)

    Iterations.

  • ips (Float)

    Average Iterations per second.

  • ips_sd (Float)

    Standard deviation of iterations per second.

  • measurement_cycle (Integer)

    Number of cycles.

Returns:



138
139
140
141
142
143
# File 'lib/benchmark/ips/report.rb', line 138

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

#dataArray<Hash<Symbol,String|Float>] Array of hashes with :label, ...

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

name:   Entry#label
ips:    Entry#ips
stddev: Entry#ips_sd

Returns:

  • (Array<Hash<Symbol,String|Float>] Array of hashes with :label, :ips, :stddev)

    Array<Hash<Symbol,String|Float>] Array of hashes with :label, :ips, :stddev



151
152
153
154
155
156
157
158
159
# File 'lib/benchmark/ips/report.rb', line 151

def data
  @data ||= @entries.collect do |entry|
    {
      :name => entry.label,
      :ips =>  entry.ips,
      :stddev => entry.ips_sd
    }
  end
end

#generate_json(path) ⇒ Object

Generate json from Report#data to given path.

Parameters:

  • path (String)

    path to generate json.



168
169
170
171
172
173
# File 'lib/benchmark/ips/report.rb', line 168

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.



162
163
164
# File 'lib/benchmark/ips/report.rb', line 162

def run_comparison
  Benchmark.compare(*@entries)
end