timocratic-test_benchmark 0.4.2 → 0.4.3
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/test_benchmark.rb +52 -27
- metadata +1 -1
data/lib/test_benchmark.rb
CHANGED
@@ -6,7 +6,8 @@ require 'test/unit/testcase'
|
|
6
6
|
require 'test/unit/ui/console/testrunner'
|
7
7
|
|
8
8
|
class Test::Unit::UI::Console::TestRunner
|
9
|
-
|
9
|
+
DISPLAY_LIMIT = 15
|
10
|
+
SUITE_DISPLAY_LIMIT = 5
|
10
11
|
|
11
12
|
alias attach_to_mediator_old attach_to_mediator
|
12
13
|
# def attach_to_mediator_old
|
@@ -25,59 +26,83 @@ class Test::Unit::UI::Console::TestRunner
|
|
25
26
|
alias started_old started
|
26
27
|
def started(result)
|
27
28
|
started_old(result)
|
28
|
-
@
|
29
|
+
@test_benchmarks = {}
|
30
|
+
@suite_benchmarks = {}
|
29
31
|
end
|
30
32
|
|
31
33
|
alias finished_old finished
|
32
34
|
def finished(elapsed_time)
|
33
35
|
finished_old(elapsed_time)
|
34
|
-
|
35
|
-
output_benchmarks(
|
36
|
-
|
37
|
-
output_benchmarks(benchmarks)
|
36
|
+
output_benchmarks
|
37
|
+
output_benchmarks(:suite)
|
38
|
+
puts "\n"
|
38
39
|
end
|
39
40
|
|
40
41
|
alias test_started_old test_started
|
41
42
|
def test_started(name)
|
42
43
|
test_started_old(name)
|
43
|
-
@
|
44
|
+
@test_benchmarks[name] = Time.now
|
44
45
|
end
|
45
46
|
|
46
47
|
alias test_finished_old test_finished
|
47
48
|
def test_finished(name)
|
48
49
|
test_finished_old(name)
|
49
|
-
@
|
50
|
+
@test_benchmarks[name] = Time.now - @test_benchmarks[name]
|
50
51
|
end
|
51
52
|
|
52
|
-
def test_suite_started(
|
53
|
+
def test_suite_started(suite_name)
|
54
|
+
@suite_benchmarks[suite_name] = Time.now
|
53
55
|
end
|
54
56
|
|
55
|
-
def test_suite_finished(
|
56
|
-
|
57
|
-
|
58
|
-
output_benchmarks(benchmarks, false, name) unless benchmarks.length == 0
|
57
|
+
def test_suite_finished(suite_name)
|
58
|
+
@suite_benchmarks[suite_name] = Time.now - @suite_benchmarks[suite_name]
|
59
|
+
output_benchmarks(suite_name) if full_output?
|
59
60
|
end
|
60
61
|
|
61
|
-
|
62
|
-
|
62
|
+
@@format_benchmark_row = lambda {|tuple| ("%0.3f" % tuple[1]) + " #{tuple[0]}"}
|
63
|
+
@@sort_by_time = lambda { |a,b| b[1] <=> a[1] }
|
64
|
+
|
65
|
+
private
|
66
|
+
def full_output?
|
67
|
+
ENV['BENCHMARK'] == 'full'
|
63
68
|
end
|
64
|
-
|
65
|
-
def
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
+
|
70
|
+
def select_by_suite_name(suite_name)
|
71
|
+
if suite_name == :suite
|
72
|
+
@suite_benchmarks.select{ |k,v| @test_benchmarks.detect{ |k1,v1| k1.include?(k) } }
|
73
|
+
elsif suite_name
|
74
|
+
@test_benchmarks.select{ |k,v| k.include?(suite_name) }
|
69
75
|
else
|
70
|
-
|
76
|
+
@test_benchmarks
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def prep_benchmarks(suite_name=nil)
|
81
|
+
benchmarks = select_by_suite_name(suite_name)
|
82
|
+
return if benchmarks.nil? || benchmarks.empty?
|
83
|
+
benchmarks = benchmarks.sort(&@@sort_by_time)
|
84
|
+
unless full_output?
|
85
|
+
cutoff = (suite_name == :suite) ? SUITE_DISPLAY_LIMIT : DISPLAY_LIMIT
|
86
|
+
benchmarks = benchmarks.slice(0, cutoff)
|
71
87
|
end
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
88
|
+
benchmarks.map(&@@format_benchmark_row)
|
89
|
+
end
|
90
|
+
|
91
|
+
def header(suite_name)
|
92
|
+
if suite_name == :suite
|
93
|
+
"\nTest Benchmark Times: Suite Totals:\n"
|
94
|
+
elsif suite_name
|
95
|
+
"\nTest Benchmark Times: #{suite_name}\n"
|
76
96
|
else
|
77
|
-
|
78
|
-
puts strings
|
97
|
+
"\nTEST BENCHMARK TIMES: OVERALL\n"
|
79
98
|
end
|
80
99
|
end
|
100
|
+
|
101
|
+
def output_benchmarks(suite_name=nil)
|
102
|
+
benchmarks = prep_benchmarks(suite_name)
|
103
|
+
return if benchmarks.nil? || benchmarks.empty?
|
104
|
+
puts header(suite_name) + benchmarks.join("\n") + "\n"
|
105
|
+
end
|
81
106
|
end
|
82
107
|
|
83
108
|
end
|