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
-
#human_format? ⇒ Boolean
private
Check if human format should be used.
-
#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 18 19 |
# File 'lib/rspec/benchmark/iteration_matcher.rb', line 12 def initialize(iterations, **) @iterations = iterations @time = .fetch(:time) { 0.2 } @warmup = .fetch(:warmup) { 0.1 } @format = .fetch(:format) { RSpec::Benchmark.configuration.format } @bench = ::Benchmark::Perf 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.
88 89 90 91 |
# 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 ⇒ 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.
83 84 85 86 |
# 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 ⇒ 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.
75 76 77 |
# File 'lib/rspec/benchmark/iteration_matcher.rb', line 75 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.
79 80 81 |
# File 'lib/rspec/benchmark/iteration_matcher.rb', line 79 def "expected block not to #{description}, but #{negative_failure_reason}" end |
#human_format? ⇒ 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.
Check if human format should be used
26 27 28 |
# File 'lib/rspec/benchmark/iteration_matcher.rb', line 26 def human_format? @format == :human end |
#ips ⇒ Object
Sugar syntax for iterations per second
71 72 73 |
# File 'lib/rspec/benchmark/iteration_matcher.rb', line 71 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.
42 43 44 45 |
# 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 ⇒ 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.
97 98 99 |
# File 'lib/rspec/benchmark/iteration_matcher.rb', line 97 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.
93 94 95 |
# File 'lib/rspec/benchmark/iteration_matcher.rb', line 93 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
35 36 37 |
# File 'lib/rspec/benchmark/iteration_matcher.rb', line 35 def supports_block_expectations? true end |
#warmup(value) ⇒ Object
The time before measurements are taken
53 54 55 56 |
# File 'lib/rspec/benchmark/iteration_matcher.rb', line 53 def warmup(value) @warmup = value self end |
#within(value) ⇒ Object
Time to measure iteration for
64 65 66 67 |
# File 'lib/rspec/benchmark/iteration_matcher.rb', line 64 def within(value) @time = value self end |