timocratic-test_benchmark 0.4.2

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.
Files changed (2) hide show
  1. data/lib/test_benchmark.rb +83 -0
  2. metadata +53 -0
@@ -0,0 +1,83 @@
1
+ unless %w{false none}.include?(ENV['BENCHMARK'])
2
+
3
+ require 'test/unit'
4
+ require 'test/unit/testresult'
5
+ require 'test/unit/testcase'
6
+ require 'test/unit/ui/console/testrunner'
7
+
8
+ class Test::Unit::UI::Console::TestRunner
9
+ include Loggable if const_defined?(:Loggable)
10
+
11
+ alias attach_to_mediator_old attach_to_mediator
12
+ # def attach_to_mediator_old
13
+ # @mediator.add_listener(TestResult::FAULT, &method(:add_fault))
14
+ # @mediator.add_listener(TestRunnerMediator::STARTED, &method(:started))
15
+ # @mediator.add_listener(TestRunnerMediator::FINISHED, &method(:finished))
16
+ # @mediator.add_listener(TestCase::STARTED, &method(:test_started))
17
+ # @mediator.add_listener(TestCase::FINISHED, &method(:test_finished))
18
+ # end
19
+ def attach_to_mediator
20
+ attach_to_mediator_old
21
+ @mediator.add_listener(Test::Unit::TestSuite::STARTED, &method(:test_suite_started))
22
+ @mediator.add_listener(Test::Unit::TestSuite::FINISHED, &method(:test_suite_finished))
23
+ end
24
+
25
+ alias started_old started
26
+ def started(result)
27
+ started_old(result)
28
+ @benchmark_times = {}
29
+ end
30
+
31
+ alias finished_old finished
32
+ def finished(elapsed_time)
33
+ finished_old(elapsed_time)
34
+ benchmarks = @benchmark_times.sort{|a, b| b[1] <=> a[1]}
35
+ output_benchmarks(benchmarks, true)
36
+ benchmarks = benchmarks.slice(0,10) unless ENV['BENCHMARK'] == 'full'
37
+ output_benchmarks(benchmarks)
38
+ end
39
+
40
+ alias test_started_old test_started
41
+ def test_started(name)
42
+ test_started_old(name)
43
+ @benchmark_times[name] = Time.now
44
+ end
45
+
46
+ alias test_finished_old test_finished
47
+ def test_finished(name)
48
+ test_finished_old(name)
49
+ @benchmark_times[name] = Time.now - @benchmark_times[name]
50
+ end
51
+
52
+ def test_suite_started(name)
53
+ end
54
+
55
+ def test_suite_finished(name)
56
+ return unless ENV['BENCHMARK'] == 'full'
57
+ benchmarks = @benchmark_times.select{ |k,v| k.include?(name) }.sort{|a, b| b[1] <=> a[1]}
58
+ output_benchmarks(benchmarks, false, name) unless benchmarks.length == 0
59
+ end
60
+
61
+ def format_benchmark_row(tuple)
62
+ ("%0.3f" % tuple[1]) + " #{tuple[0]}"
63
+ end
64
+
65
+ def output_benchmarks(benchmarks, use_logger=false, name=nil)
66
+ return if use_logger && !defined?(logger)
67
+ if name
68
+ header = "\nTest Benchmark Times: #{name}"
69
+ else
70
+ header = "\nOVERALL TEST BENCHMARK TIMES"
71
+ end
72
+ strings = benchmarks.map {|tuple| format_benchmark_row(tuple)}
73
+ if use_logger
74
+ logger.debug header
75
+ logger.debug strings.join("\n")
76
+ else
77
+ puts header
78
+ puts strings
79
+ end
80
+ end
81
+ end
82
+
83
+ end
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: timocratic-test_benchmark
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.2
5
+ platform: ruby
6
+ authors:
7
+ - Tim Connor
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-01-13 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: timocratic@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - lib/test_benchmark.rb
26
+ has_rdoc: false
27
+ homepage: http://github.com/timocratic/test_benchmark
28
+ post_install_message:
29
+ rdoc_options: []
30
+
31
+ require_paths:
32
+ - lib
33
+ required_ruby_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: "0"
38
+ version:
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
45
+ requirements: []
46
+
47
+ rubyforge_project:
48
+ rubygems_version: 1.2.0
49
+ signing_key:
50
+ specification_version: 2
51
+ summary: "Rails plugin (and/or ruby gem) for benchmarking your test::units: a rework of the original by topfunky"
52
+ test_files: []
53
+