Module: ActiveSupport::Testing::Performance

Extended by:
Concern
Included in:
ActionDispatch::PerformanceTest
Defined in:
lib/rails/perftest/active_support/testing/performance.rb,
lib/rails/perftest/active_support/testing/performance/ruby.rb,
lib/rails/perftest/active_support/testing/performance/jruby.rb,
lib/rails/perftest/active_support/testing/performance/rubinius.rb

Defined Under Namespace

Modules: Metrics, Minitest4AndLower, Minitest5AndGreater Classes: Benchmarker, Performer, Profiler

Constant Summary collapse

DEFAULTS =

each implementation should define metrics and freeze the defaults

if ENV["BENCHMARK_TESTS"]
  { :runs => 4,
    :output => 'tmp/performance',
    :benchmark => true }
else
  { :runs => 1,
    :output => 'tmp/performance',
    :benchmark => false }
end

Instance Method Summary collapse

Instance Method Details

#_performance_runObject



66
67
68
69
70
71
72
73
74
75
# File 'lib/rails/perftest/active_support/testing/performance.rb', line 66

def _performance_run
  run_warmup
  if full_profile_options && metrics = full_profile_options[:metrics]
    metrics.each do |metric_name|
      if klass = Metrics[metric_name.to_sym]
        run_profile(klass.new)
      end
    end
  end
end

#full_profile_optionsObject



30
31
32
# File 'lib/rails/perftest/active_support/testing/performance.rb', line 30

def full_profile_options
  DEFAULTS.merge(profile_options)
end

#full_test_nameObject



34
35
36
# File 'lib/rails/perftest/active_support/testing/performance.rb', line 34

def full_test_name
  "#{self.class.name}##{method_name}"
end

#run_test(metric, mode) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/rails/perftest/active_support/testing/performance.rb', line 77

def run_test(metric, mode)
  result = '.'
  begin
    before_setup
    setup
    after_setup
    metric.send(mode) { __send__ method_name }
  rescue Exception => e
    result = performance_failure(e)
  ensure
    begin
      before_teardown
      teardown
      after_teardown
    rescue Exception => e
      result = performance_failure(e)
    end
  end
  result
end