class RSpec::Core::Notifications::ProfileNotification

@attr example_groups [Array<RSpec::Core::Profiler>] example groups run
@attr number_of_examples [Fixnum] the number of examples to profile
@attr examples [Array<RSpec::Core::Example>] the examples run
@attr duration [Float] the time taken (in seconds) to run the suite
information at the end of the test run for profiling information.
test suite when profiling is enabled. It is used by formatters to provide
The ‘ProfileNotification` holds information about the results of running a

def calculate_slowest_groups

def calculate_slowest_groups
  # stop if we've only one example group
  return {} if @example_groups.keys.length <= 1
  @example_groups.each_value do |hash|
    hash[:average] = hash[:total_time].to_f / hash[:count]
  end
  groups = @example_groups.sort_by { |_, hash| -hash[:average] }.first(number_of_examples)
  groups.map { |group, data| [group.location, data] }
end

def initialize(duration, examples, number_of_examples, example_groups)

def initialize(duration, examples, number_of_examples, example_groups)
  @duration = duration
  @examples = examples
  @number_of_examples = number_of_examples
  @example_groups = example_groups
end

def percentage

Returns:
  • (String) - the percentage of total time taken
def percentage
  @percentage ||=
    begin
      time_taken = slow_duration / duration
      '%.1f' % ((time_taken.nan? ? 0.0 : time_taken) * 100)
    end
end

def slow_duration

Returns:
  • (Float) - the time taken (in seconds) to run the slowest examples
def slow_duration
  @slow_duration ||=
    slowest_examples.inject(0.0) do |i, e|
      i + e.execution_result.run_time
    end
end

def slowest_examples

Returns:
  • (Array) - the slowest examples
def slowest_examples
  @slowest_examples ||=
    examples.sort_by do |example|
      -example.execution_result.run_time
    end.first(number_of_examples)
end

def slowest_groups

Returns:
  • (Array) - the slowest example groups
def slowest_groups
  @slowest_groups ||= calculate_slowest_groups
end