class RSpec::Benchmark::IterationMatcher::Matcher

Implements the `perform_at_least` matcher

@api private

Public Class Methods

new(iterations, **options) click to toggle source
# File lib/rspec/benchmark/iteration_matcher.rb, line 12
def initialize(iterations, **options)
  @iterations = iterations
  @time       = options.fetch(:time) { 0.2 }
  @warmup     = options.fetch(:warmup) { 0.1 }
  @format     = options.fetch(:format) {
                  RSpec::Benchmark.configuration.format }
  @bench      = ::Benchmark::Perf
end

Public Instance Methods

actual() click to toggle source
# File lib/rspec/benchmark/iteration_matcher.rb, line 88
def actual
  avg = human_format? ? Formatter.format_unit(@average) : @average
  "%s (± %d%%) i/s" % [avg, (@stddev / @average.to_f) * 100]
end
description() click to toggle source
# File lib/rspec/benchmark/iteration_matcher.rb, line 83
def description
  iters = human_format? ? Formatter.format_unit(@iterations) : @iterations
  "perform at least #{iters} i/s"
end
failure_message() click to toggle source
# File lib/rspec/benchmark/iteration_matcher.rb, line 75
def failure_message
  "expected block to #{description}, but #{positive_failure_reason}"
end
failure_message_when_negated() click to toggle source
# File lib/rspec/benchmark/iteration_matcher.rb, line 79
def failure_message_when_negated
  "expected block not to #{description}, but #{negative_failure_reason}"
end
human_format?() click to toggle source

Check if human format should be used

@return [Boolean]

@api private

# File lib/rspec/benchmark/iteration_matcher.rb, line 26
def human_format?
  @format == :human
end
ips() click to toggle source

Sugar syntax for iterations per second @api public

# File lib/rspec/benchmark/iteration_matcher.rb, line 71
def ips
  self
end
matches?(block) click to toggle source

@return [Boolean]

@api private

# File lib/rspec/benchmark/iteration_matcher.rb, line 42
def matches?(block)
  @average, @stddev, = @bench.ips(time: @time, warmup: @warmup, &block)
  @iterations <= (@average + 3 * @stddev)
end
negative_failure_reason() click to toggle source
# File lib/rspec/benchmark/iteration_matcher.rb, line 97
def negative_failure_reason
  "performed #{actual}"
end
positive_failure_reason() click to toggle source
# File lib/rspec/benchmark/iteration_matcher.rb, line 93
def positive_failure_reason
  "performed only #{actual}"
end
supports_block_expectations?() click to toggle source

Indicates this matcher matches against a block

@return [True]

@api private

# File lib/rspec/benchmark/iteration_matcher.rb, line 35
def supports_block_expectations?
  true
end
warmup(value) click to toggle source

The time before measurements are taken

@param [Numeric] value

the time before measurements are taken

@api public

# File lib/rspec/benchmark/iteration_matcher.rb, line 53
def warmup(value)
  @warmup = value
  self
end
within(value) click to toggle source

Time to measure iteration for

@param [Numeric] value

the time to take measurements for

@api public

# File lib/rspec/benchmark/iteration_matcher.rb, line 64
def within(value)
  @time = value
  self
end