class RSpec::Benchmark::TimingMatcher::Matcher
Implements the `perform_under` matcher
@api private
Attributes
threshold[R]
Public Class Methods
new(threshold, **options)
click to toggle source
# File lib/rspec/benchmark/timing_matcher.rb, line 18 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
Public Instance Methods
actual()
click to toggle source
# File lib/rspec/benchmark/timing_matcher.rb, line 122 def actual "#{Formatter.format_time(@average)} (± #{Formatter.format_time(@stddev)})" end
description()
click to toggle source
# File lib/rspec/benchmark/timing_matcher.rb, line 118 def description "perform under #{Formatter.format_time(@threshold)}" end
does_not_match?(block)
click to toggle source
# File lib/rspec/benchmark/timing_matcher.rb, line 52 def does_not_match?(block) !matches?(block) && block.is_a?(Proc) end
failure_message()
click to toggle source
# File lib/rspec/benchmark/timing_matcher.rb, line 110 def failure_message "expected block to #{description}, but #{positive_failure_reason}" end
failure_message_when_negated()
click to toggle source
# File lib/rspec/benchmark/timing_matcher.rb, line 114 def failure_message_when_negated "expected block to not #{description}, but #{negative_failure_reason}" end
matches?(block)
click to toggle source
@return [Boolean]
@api private
# File lib/rspec/benchmark/timing_matcher.rb, line 44 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
ms()
click to toggle source
Tell this matcher to convert threshold to ms @api public
# File lib/rspec/benchmark/timing_matcher.rb, line 91 def ms @threshold /= 1e3 self end
negative_failure_reason()
click to toggle source
# File lib/rspec/benchmark/timing_matcher.rb, line 131 def negative_failure_reason return "was not a block" unless @block.is_a?(Proc) "performed #{actual} under" end
ns()
click to toggle source
Tell this matcher to convert threshold to ns @api public
# File lib/rspec/benchmark/timing_matcher.rb, line 105 def ns @threshold /= 1e9 self end
positive_failure_reason()
click to toggle source
# File lib/rspec/benchmark/timing_matcher.rb, line 126 def positive_failure_reason return "was not a block" unless @block.is_a?(Proc) "performed above #{actual} " end
sample(samples)
click to toggle source
How many times to repeat measurement
@param [Integer] samples
the number of times to repeat the measurement
@api public
# File lib/rspec/benchmark/timing_matcher.rb, line 73 def sample(samples) @samples = samples self end
secs()
click to toggle source
# File lib/rspec/benchmark/timing_matcher.rb, line 84 def secs self end
Also aliased as: sec
supports_block_expectations?()
click to toggle source
Indicates this matcher matches against a block
@return [True]
@api private
# File lib/rspec/benchmark/timing_matcher.rb, line 37 def supports_block_expectations? true end
times()
click to toggle source
No-op, syntactic sugar. @api public
# File lib/rspec/benchmark/timing_matcher.rb, line 80 def times self end
us()
click to toggle source
Tell this matcher to convert threshold to us @api public
# File lib/rspec/benchmark/timing_matcher.rb, line 98 def us @threshold /= 1e6 self 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/timing_matcher.rb, line 62 def warmup(value) @warmup = value self end