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 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

#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(runner) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/rails/perftest/active_support/testing/performance.rb', line 38

def run(runner)
  @runner = runner

  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

  return
end

#run_test(metric, mode) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/rails/perftest/active_support/testing/performance.rb', line 53

def run_test(metric, mode)
  result = '.'
  begin
    run_callbacks :setup
    setup
    metric.send(mode) { __send__ method_name }
  rescue Exception => e
    result = @runner.puke(self.class, method_name, e)
  ensure
    begin
      teardown
      run_callbacks :teardown
    rescue Exception => e
      result = @runner.puke(self.class, method_name, e)
    end
  end
  result
end