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 +7 -7
- data/lib/rbench/group.rb +1 -1
- data/lib/rbench/report.rb +5 -2
- data/lib/rbench/summary.rb +31 -7
- data/spec/rbench_spec.rb +1 -1
- metadata +1 -1
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(
|
15
|
-
str = case
|
16
|
-
when Array then "%#{width-1}.2f" % (
|
17
|
-
when Float then "%#{width}.3f" %
|
18
|
-
when Integer then "%#{width}.0f" %
|
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" % (
|
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
|
-
|
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
|
data/lib/rbench/summary.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module RBench
|
2
|
-
class Summary
|
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
|
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.
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
-
|
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