module ActiveSupport::Testing::Performance

Constants

DEFAULTS

Public Instance Methods

full_test_name() click to toggle source
# File lib/active_support/testing/performance.rb, line 32
def full_test_name
  "#{self.class.name}##{method_name}"
end
run(result) { |STARTED, name| ... } click to toggle source
# File lib/active_support/testing/performance.rb, line 36
def run(result)
  return if method_name =~ %r^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) click to toggle source
# File lib/active_support/testing/performance.rb, line 55
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 => e
  add_error(e)
ensure
  begin
    teardown
    run_callbacks :teardown, :enumerator => :reverse_each
  rescue ::Test::Unit::AssertionFailedError => e
    add_failure(e.message, e.backtrace)
  rescue StandardError, ScriptError => e
    add_error(e)
  end
end

Protected Instance Methods

run_profile(metric) click to toggle source
# File lib/active_support/testing/performance.rb, line 85
def run_profile(metric)
  klass = profile_options[:benchmark] ? Benchmarker : Profiler
  performer = klass.new(self, metric)

  performer.run
  puts performer.report
  performer.record
end
run_warmup() click to toggle source
# File lib/active_support/testing/performance.rb, line 75
def run_warmup
  GC.start

  time = Metrics::Time.new
  run_test(time, :benchmark)
  puts "%s (%s warmup)" % [full_test_name, time.format(time.total)]

  GC.start
end

Public Class Methods

included(base) click to toggle source
# File lib/active_support/testing/performance.rb, line 27
def self.included(base)
  base.superclass_delegating_accessor :profile_options
  base.profile_options = DEFAULTS
end