Class: RSpec::Benchmark::IterationMatcher::Matcher Private
- Inherits:
-
Object
- Object
- RSpec::Benchmark::IterationMatcher::Matcher
- Defined in:
- lib/rspec/benchmark/iteration_matcher.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Implements the ‘perform_at_least` matcher
Instance Method Summary collapse
- #actual ⇒ Object private
- #description ⇒ Object private
- #failure_message ⇒ Object private
- #failure_message_when_negated ⇒ Object private
-
#initialize(iterations, **options) ⇒ Matcher
constructor
private
A new instance of Matcher.
-
#ips ⇒ Object
Sugar syntax for iterations per second.
- #matches?(block) ⇒ Boolean private
- #negative_failure_reason ⇒ Object private
- #positive_failure_reason ⇒ Object private
-
#supports_block_expectations? ⇒ True
private
Indicates this matcher matches against a block.
-
#warmup(value) ⇒ Object
The time before measurements are taken.
-
#within(value) ⇒ Object
Time to measure iteration for.
Constructor Details
#initialize(iterations, **options) ⇒ Matcher
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Matcher.
12 13 14 15 16 17 |
# File 'lib/rspec/benchmark/iteration_matcher.rb', line 12 def initialize(iterations, **) @iterations = iterations @time = .fetch(:time) { 0.2 } @warmup = .fetch(:warmup) { 0.1 } @bench = ::Benchmark::Perf::Iteration end |
Instance Method Details
#actual ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
76 77 78 |
# File 'lib/rspec/benchmark/iteration_matcher.rb', line 76 def actual "%d (± %d%%) i/s" % [@average, (@stddev / @average.to_f) * 100] end |
#description ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
72 73 74 |
# File 'lib/rspec/benchmark/iteration_matcher.rb', line 72 def description "perform at least #{@iterations} i/s" end |
#failure_message ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
64 65 66 |
# File 'lib/rspec/benchmark/iteration_matcher.rb', line 64 def "expected block to #{description}, but #{positive_failure_reason}" end |
#failure_message_when_negated ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
68 69 70 |
# File 'lib/rspec/benchmark/iteration_matcher.rb', line 68 def "expected block not to #{description}, but #{negative_failure_reason}" end |
#ips ⇒ Object
Sugar syntax for iterations per second
60 61 62 |
# File 'lib/rspec/benchmark/iteration_matcher.rb', line 60 def ips self end |
#matches?(block) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
31 32 33 34 |
# File 'lib/rspec/benchmark/iteration_matcher.rb', line 31 def matches?(block) @average, @stddev, = @bench.run(time: @time, warmup: @warmup, &block) @iterations <= (@average + 3 * @stddev) end |
#negative_failure_reason ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
84 85 86 |
# File 'lib/rspec/benchmark/iteration_matcher.rb', line 84 def negative_failure_reason "performed #{actual}" end |
#positive_failure_reason ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
80 81 82 |
# File 'lib/rspec/benchmark/iteration_matcher.rb', line 80 def positive_failure_reason "performed only #{actual}" end |
#supports_block_expectations? ⇒ True
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Indicates this matcher matches against a block
24 25 26 |
# File 'lib/rspec/benchmark/iteration_matcher.rb', line 24 def supports_block_expectations? true end |
#warmup(value) ⇒ Object
The time before measurements are taken
42 43 44 45 |
# File 'lib/rspec/benchmark/iteration_matcher.rb', line 42 def warmup(value) @warmup = value self end |
#within(value) ⇒ Object
Time to measure iteration for
53 54 55 56 |
# File 'lib/rspec/benchmark/iteration_matcher.rb', line 53 def within(value) @time = value self end |