Class: Benchmark::IPS::Report
- Inherits:
-
Object
- Object
- Benchmark::IPS::Report
- 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
-
#entries ⇒ Array<Report::Entry>
readonly
Entry to represent each benchmarked code in Report.
Instance Method Summary collapse
-
#add_entry(label, microseconds, iters, stats, measurement_cycle) ⇒ Report::Entry
Add entry to report.
-
#data ⇒ Array<Hash<Symbol,String|Float|Integer>] Array of hashes
Entries data in array for generate json.
-
#generate_json(path) ⇒ Object
Generate json from Report#data to given path.
-
#initialize ⇒ Report
constructor
Instantiate the Report.
-
#run_comparison(order) ⇒ Object
Run comparison of entries.
Constructor Details
#initialize ⇒ Report
Instantiate the Report.
135 136 137 138 |
# File 'lib/benchmark/ips/report.rb', line 135 def initialize @entries = [] @data = nil end |
Instance Attribute Details
#entries ⇒ Array<Report::Entry> (readonly)
Entry to represent each benchmarked code in Report.
132 133 134 |
# File 'lib/benchmark/ips/report.rb', line 132 def entries @entries end |
Instance Method Details
#add_entry(label, microseconds, iters, stats, measurement_cycle) ⇒ Report::Entry
Add entry to report.
147 148 149 150 151 152 |
# File 'lib/benchmark/ips/report.rb', line 147 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 ⇒ Array<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
163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/benchmark/ips/report.rb', line 163 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.
185 186 187 188 189 190 191 192 193 194 |
# File 'lib/benchmark/ips/report.rb', line 185 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 |