Class: ImageOptim::Runner::BenchmarkResults
- Inherits:
-
Object
- Object
- ImageOptim::Runner::BenchmarkResults
- Defined in:
- lib/image_optim/runner.rb
Overview
files, elapsed, kb saved, kb/s
Instance Method Summary collapse
- #add(rows) ⇒ Object
-
#initialize ⇒ BenchmarkResults
constructor
A new instance of BenchmarkResults.
- #print ⇒ Object
Constructor Details
#initialize ⇒ BenchmarkResults
Returns a new instance of BenchmarkResults.
50 51 52 |
# File 'lib/image_optim/runner.rb', line 50 def initialize @all = [] end |
Instance Method Details
#add(rows) ⇒ Object
54 55 56 |
# File 'lib/image_optim/runner.rb', line 54 def add(rows) @all.concat(rows) end |
#print ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/image_optim/runner.rb', line 58 def print if @all.empty? puts 'nothing to report' return end report = @all.group_by(&:worker).map do |name, results| kb = (results.sum(&:bytes) / 1024.0) elapsed = results.sum(&:elapsed) { 'name' => name, 'files' => results.length, 'elapsed' => elapsed, 'kb saved' => kb, 'kb/s' => (kb / elapsed), } end report = report.sort_by do |row| [-row['kb/s'], row['name']] end puts "\nBENCHMARK RESULTS\n\n" Table.new(report).write($stdout) end |