Class: RBench::Summary
- Inherits:
-
Object
- Object
- RBench::Summary
- Defined in:
- lib/rbench/summary.rb
Instance Attribute Summary collapse
-
#cells ⇒ Object
readonly
Returns the value of attribute cells.
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#lines ⇒ Object
Returns the value of attribute lines.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#runner ⇒ Object
readonly
Returns the value of attribute runner.
Instance Method Summary collapse
-
#initialize(runner, group, name) ⇒ Summary
constructor
A new instance of Summary.
- #run ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(runner, group, name) ⇒ Summary
Returns a new instance of Summary.
6 7 8 9 10 11 12 |
# File 'lib/rbench/summary.rb', line 6 def initialize(runner, group, name) @runner = runner @group = group @name = name @cells = {} # A hash with keys as columns, and values being the result @items = [] end |
Instance Attribute Details
#cells ⇒ Object (readonly)
Returns the value of attribute cells.
3 4 5 |
# File 'lib/rbench/summary.rb', line 3 def cells @cells end |
#items ⇒ Object (readonly)
Returns the value of attribute items.
3 4 5 |
# File 'lib/rbench/summary.rb', line 3 def items @items end |
#lines ⇒ Object
Returns the value of attribute lines.
4 5 6 |
# File 'lib/rbench/summary.rb', line 4 def lines @lines end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/rbench/summary.rb', line 3 def name @name end |
#runner ⇒ Object (readonly)
Returns the value of attribute runner.
3 4 5 |
# File 'lib/rbench/summary.rb', line 3 def runner @runner end |
Instance Method Details
#run ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rbench/summary.rb', line 14 def run # maybe add convenience-method to group to. group == runner really. items = (@group ? @group.items & @runner.reports : @runner.reports) rows = items.map{|item| item.cells.values_at(*@runner.columns.map{|c|c.name}) } rows = rows.pop.zip(*rows) @runner.columns.each_with_index do |c,i| if c.compare value,comparisons = 0,0 items.each do |item| v1,v2 = *item.cells.values_at(*c.compare) if v1.kind_of?(Numeric) && v2.kind_of?(Numeric) && v1 != 0 && v2 != 0 value += v1 / v2 comparisons += 1 end end @cells[c.name] = [value,comparisons] if comparisons > 0 elsif c.name != :times @cells[c.name] = rows[i].compact.select{|r| r.kind_of?(Numeric)}.inject(0){|tot,v| tot += v.to_f } end end puts to_s end |
#to_s ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rbench/summary.rb', line 40 def to_s out = "" out << @runner.separator(nil,"=") + @runner.newline unless @group out << "%-#{@runner.desc_width}s" % name @runner.columns.each do |column| value = @cells[column.name] out << column.to_s( value ) end out << @runner.newline end |