somebee-rbench 0.2 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/rbench/column.rb CHANGED
@@ -11,16 +11,16 @@ module RBench
11
11
  @default = @compare ? @compare : options[:default]
12
12
  end
13
13
 
14
- def to_s(value=title)
15
- str = case value
16
- when Array then "%#{width-1}.2f" % (value[0] / value[1]) + "x"
17
- when Float then "%#{width}.3f" % value
18
- when Integer then "%#{width}.0f" % value
14
+ def to_s(val=title)
15
+ str = case val
16
+ when Array then "%#{width-1}.2f" % (val[0] / val[1]) + "x"
17
+ when Float then "%#{width}.3f" % val
18
+ when Integer then "%#{width}.0f" % val
19
19
  when TrueClass then " "*(width/2.0).floor + "X" + " "*(width/2.0).floor
20
- when String then "%#{width}s" % (value)[0,width]
20
+ when String then "%#{width}s" % (val)[0,width]
21
21
  when Object then " " * width
22
22
  end
23
- return " #{(str+" "*width)[0,width]} |"
23
+ return " #{(str.to_s+" "*width)[0,width]} |"
24
24
  end
25
25
  end
26
26
  end
data/lib/rbench/group.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module RBench
2
2
  class Group
3
3
  self.instance_methods.each do |m|
4
- send(:undef_method, m) unless m =~ /^(__|is_a?|kind_of?|respond_to?|inspect|instance_eval)/
4
+ send(:undef_method, m) unless m =~ /^(__|is_a?|kind_of?|respond_to?|hash|eql?|inspect|instance_eval)/
5
5
  end
6
6
 
7
7
  attr_reader :name, :items, :block
data/lib/rbench/report.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module RBench
2
2
  class Report
3
3
  self.instance_methods.each do |m|
4
- send(:undef_method, m) unless m =~ /^(__|is_a?|kind_of?|respond_to?|inspect|instance_eval)/
4
+ send(:undef_method, m) unless m =~ /^(__|is_a?|kind_of?|respond_to?|hash|inspect|instance_eval|eql?)/
5
5
  end
6
6
 
7
7
  attr_reader :name, :cells
@@ -42,7 +42,10 @@ module RBench
42
42
  out = "%-#{@runner.desc_width}s" % name
43
43
  @runner.columns.each do |column|
44
44
  value = @cells[column.name]
45
- out << column.to_s(value.is_a?(Array) ? @cells.values_at(*value) : value )
45
+ value = @cells.values_at(*value) if value.is_a?(Array)
46
+ value = nil if value.is_a?(Array) && value.nitems != 2
47
+
48
+ out << column.to_s(value)
46
49
  end
47
50
  out << @runner.newline
48
51
  end
@@ -1,5 +1,5 @@
1
1
  module RBench
2
- class Summary < Report
2
+ class Summary
3
3
  attr_reader :name, :runner, :cells, :items
4
4
  attr_accessor :lines
5
5
 
@@ -13,15 +13,39 @@ module RBench
13
13
 
14
14
  def run
15
15
  # maybe add convenience-method to group to. group == runner really.
16
- items = @group ? @group.items.select{|i| i.is_a?(Report)} : @runner.reports
16
+ items = (@group ? @group.items & @runner.reports : @runner.reports)
17
+
18
+ rows = items.map{|item| item.cells.values_at(*@runner.columns.map{|c|c.name}) }
19
+ rows = rows.pop.zip(*rows)
17
20
 
18
- @runner.columns.each do |c|
19
- # TODO: Get number of fields that was counted in, and /
20
- value = items.inject(0){|tot,i| v = i.cells[c.name]; tot += v.kind_of?(Numeric) ? v : 0 }
21
- @cells[c.name] = value == 0 ? "" : value
21
+ @runner.columns.each_with_index do |c,i|
22
+ if c.compare
23
+ value,comparisons = 0,0
24
+ items.each do |item|
25
+ v1,v2 = *item.cells.values_at(*c.compare)
26
+ if v1.kind_of?(Numeric) && v2.kind_of?(Numeric) && v1 != 0 && v2 != 0
27
+ value += v1 / v2
28
+ comparisons += 1
29
+ end
30
+ end
31
+ @cells[c.name] = [value,comparisons] if comparisons > 0
32
+ else
33
+ @cells[c.name] = rows[i].compact.select{|r| r.kind_of?(Numeric)}.inject(0){|tot,v| tot += v.to_f }
34
+ end
22
35
  end
23
- puts @runner.separator(nil,"=") unless @group
36
+
24
37
  puts to_s
25
38
  end
39
+
40
+ def to_s
41
+ out = ""
42
+ out << @runner.separator(nil,"=") + @runner.newline unless @group
43
+ out << "%-#{@runner.desc_width}s" % name
44
+ @runner.columns.each do |column|
45
+ value = @cells[column.name]
46
+ out << column.to_s( value )
47
+ end
48
+ out << @runner.newline
49
+ end
26
50
  end
27
51
  end
data/spec/rbench_spec.rb CHANGED
@@ -90,7 +90,7 @@ bench = RBench.run(TIMES) do
90
90
 
91
91
  report "match" do
92
92
  dm { "aaa/aaa/aaa.bbb.ccc.ddd".match(/\.([^\.]*)$/) }
93
- ar { "aaa//aaa//aaa.bbb.ccc.ddd.eee".match(/\.([^\.]*)$/) }
93
+ #ar { "aaa//aaa//aaa.bbb.ccc.ddd.eee".match(/\.([^\.]*)$/) }
94
94
  end
95
95
 
96
96
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: somebee-rbench
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.2"
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yehuda Katz & Sindre Aarsaether