Module: ActiveSupport::Testing::Performance
- Defined in:
- lib/active_support/testing/performance.rb
Defined Under Namespace
Modules: Metrics
Classes: Benchmarker, Performer, Profiler
Constant Summary
collapse
- DEFAULTS =
if benchmark = ARGV.include?('--benchmark') { :benchmark => true,
:runs => 4,
:metrics => [:wall_time, :memory, :objects, :gc_runs, :gc_time],
:output => 'tmp/performance' }
else
{ :benchmark => false,
:runs => 1,
:min_percent => 0.01,
:metrics => [:process_time, :memory, :objects],
:formats => [:flat, :graph_html, :call_tree],
:output => 'tmp/performance' }
end.freeze
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.included(base) ⇒ Object
26
27
28
29
|
# File 'lib/active_support/testing/performance.rb', line 26
def self.included(base)
base.class_attribute :profile_options
base.profile_options = DEFAULTS
end
|
Instance Method Details
#full_test_name ⇒ Object
31
32
33
|
# File 'lib/active_support/testing/performance.rb', line 31
def full_test_name
"#{self.class.name}##{method_name}"
end
|
#run(result) {|self.class::STARTED, name| ... } ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/active_support/testing/performance.rb', line 35
def run(result)
return if method_name =~ /^default_test$/
yield(self.class::STARTED, name)
@_result = result
run_warmup
if profile_options && metrics = profile_options[:metrics]
metrics.each do |metric_name|
if klass = Metrics[metric_name.to_sym]
run_profile(klass.new)
result.add_run
end
end
end
yield(self.class::FINISHED, name)
end
|
#run_test(metric, mode) ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/active_support/testing/performance.rb', line 54
def run_test(metric, mode)
run_callbacks :setup
setup
metric.send(mode) { __send__ @method_name }
rescue ::Test::Unit::AssertionFailedError => e
add_failure(e.message, e.backtrace)
rescue StandardError, ScriptError
add_error($!)
ensure
begin
teardown
run_callbacks :teardown, :enumerator => :reverse_each
rescue ::Test::Unit::AssertionFailedError => e
add_failure(e.message, e.backtrace)
rescue StandardError, ScriptError
add_error($!)
end
end
|