Module: RSpec::Benchmark::Matchers
- Defined in:
- lib/rspec/benchmark/matchers.rb
Overview
Provides a number of useful performance testing expectations
These matchers can be exposed by including the this module in a spec:
RSpec.describe "Performance testing" do
include RSpec::Benchmark::Matchers
end
or you can include in globablly in a spec_helper.rb file:
RSpec.configure do |config|
config.inlucde(RSpec::Benchmark::Matchers)
end
Instance Method Summary collapse
-
#bench_range(*args) ⇒ Object
Generate a geometric progression of inputs.
-
#perform_allocation(objects, **options) ⇒ Object
Passes if code block performs at least iterations.
-
#perform_at_least(iterations, **options) ⇒ Object
Passes if code block performs at least iterations.
-
#perform_constant(**options) ⇒ Object
Pass if code block performs constant.
-
#perform_exponential(**options) ⇒ Object
(also: #perform_exp)
Pass if code block performs exponential.
-
#perform_faster_than(**options, &sample) ⇒ Object
Passes if code block performs faster than sample block.
-
#perform_linear(**options) ⇒ Object
Pass if code block performs linear.
-
#perform_logarithmic(**options) ⇒ Object
(also: #perform_log)
Pass if code block performs logarithmic.
-
#perform_power(**options) ⇒ Object
Pass if code block performs power.
-
#perform_slower_than(**options, &sample) ⇒ Object
Passes if code block performs slower than sample block.
-
#perform_under(threshold, **options) ⇒ Object
Passes if code block performs under threshold.
Instance Method Details
#bench_range(*args) ⇒ Object
Generate a geometric progression of inputs
The default range is generated in the multiples of 8.
170 171 172 |
# File 'lib/rspec/benchmark/matchers.rb', line 170 def bench_range(*args) ::Benchmark::Trend.range(*args) end |
#perform_allocation(objects, **options) ⇒ Object
Passes if code block performs at least iterations
37 38 39 |
# File 'lib/rspec/benchmark/matchers.rb', line 37 def perform_allocation(objects, **) AllocationMatcher::Matcher.new(objects, **) end |
#perform_at_least(iterations, **options) ⇒ Object
Passes if code block performs at least iterations
50 51 52 |
# File 'lib/rspec/benchmark/matchers.rb', line 50 def perform_at_least(iterations, **) IterationMatcher::Matcher.new(iterations, **) end |
#perform_constant(**options) ⇒ Object
Pass if code block performs constant
102 103 104 |
# File 'lib/rspec/benchmark/matchers.rb', line 102 def perform_constant(**) ComplexityMatcher::Matcher.new(:constant, **) end |
#perform_exponential(**options) ⇒ Object Also known as: perform_exp
Pass if code block performs exponential
152 153 154 |
# File 'lib/rspec/benchmark/matchers.rb', line 152 def perform_exponential(**) ComplexityMatcher::Matcher.new(:exponential, **) end |
#perform_faster_than(**options, &sample) ⇒ Object
Passes if code block performs faster than sample block
77 78 79 |
# File 'lib/rspec/benchmark/matchers.rb', line 77 def perform_faster_than(**, &sample) ComparisonMatcher::Matcher.new(sample, :faster, **) end |
#perform_linear(**options) ⇒ Object
Pass if code block performs linear
128 129 130 |
# File 'lib/rspec/benchmark/matchers.rb', line 128 def perform_linear(**) ComplexityMatcher::Matcher.new(:linear, **) end |
#perform_logarithmic(**options) ⇒ Object Also known as: perform_log
Pass if code block performs logarithmic
115 116 117 |
# File 'lib/rspec/benchmark/matchers.rb', line 115 def perform_logarithmic(**) ComplexityMatcher::Matcher.new(:logarithmic, **) end |
#perform_power(**options) ⇒ Object
Pass if code block performs power
140 141 142 |
# File 'lib/rspec/benchmark/matchers.rb', line 140 def perform_power(**) ComplexityMatcher::Matcher.new(:power, **) end |
#perform_slower_than(**options, &sample) ⇒ Object
Passes if code block performs slower than sample block
90 91 92 |
# File 'lib/rspec/benchmark/matchers.rb', line 90 def perform_slower_than(**, &sample) ComparisonMatcher::Matcher.new(sample, :slower, **) end |
#perform_under(threshold, **options) ⇒ Object
Passes if code block performs under threshold
64 65 66 |
# File 'lib/rspec/benchmark/matchers.rb', line 64 def perform_under(threshold, **) TimingMatcher::Matcher.new(threshold, **) end |