class RSpec::Benchmark::TimingMatcher::Matcher

@api private
Implements the ‘perform_under` matcher

def actual

def actual
  "#{Formatter.format_time(@average)}#{Formatter.format_time(@stddev)})"
end

def description

def description
  "perform under #{Formatter.format_time(@threshold)}"
end

def does_not_match?(block)

def does_not_match?(block)
  !matches?(block) && block.is_a?(Proc)
end

def failure_message

def failure_message
  "expected block to #{description}, but #{positive_failure_reason}"
end

def failure_message_when_negated

def failure_message_when_negated
  "expected block to not #{description}, but #{negative_failure_reason}"
end

def initialize(threshold, **options)

def initialize(threshold, **options)
  @threshold = threshold
  @samples   = options.fetch(:samples) {
                 RSpec::Benchmark.configuration.samples
               }
  @warmup    = options.fetch(:warmup) { 1 }
  @subprocess = options.fetch(:subprocess) {
                  RSpec::Benchmark.configuration.run_in_subprocess
                }
  @scale     = threshold.to_s.split(/\./).last.size
  @block     = nil
  @bench     = ::Benchmark::Perf
end

def matches?(block)

Other tags:
    Api: - private

Returns:
  • (Boolean) -
def matches?(block)
  @block = block
  return false unless block.is_a?(Proc)
  @average, @stddev = @bench.cpu(repeat: @samples, warmup: @warmup,
                                 subprocess: @subprocess, &block)
  @average <= @threshold
end

def ms

Other tags:
    Api: - public
def ms
  @threshold /= 1e3
  self
end

def negative_failure_reason

def negative_failure_reason
  return "was not a block" unless @block.is_a?(Proc)
  "performed #{actual} under"
end

def ns

Other tags:
    Api: - public
def ns
  @threshold /= 1e9
  self
end

def positive_failure_reason

def positive_failure_reason
  return "was not a block" unless @block.is_a?(Proc)
  "performed above #{actual} "
end

def sample(samples)

Other tags:
    Api: - public

Parameters:
  • samples (Integer) --
def sample(samples)
  @samples = samples
  self
end

def secs

def secs
  self
end

def supports_block_expectations?

Other tags:
    Api: - private

Returns:
  • (True) -
def supports_block_expectations?
  true
end

def times

Other tags:
    Api: - public
def times
  self
end

def us

Other tags:
    Api: - public
def us
  @threshold /= 1e6
  self
end

def warmup(value)

Other tags:
    Api: - public

Parameters:
  • value (Numeric) --
def warmup(value)
  @warmup = value
  self
end