rspec-benchmark 0.5.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +18 -0
- data/README.md +14 -1
- data/lib/rspec-benchmark.rb +1 -1
- data/lib/rspec/benchmark.rb +3 -3
- data/lib/rspec/benchmark/allocation_matcher.rb +6 -6
- data/lib/rspec/benchmark/comparison_matcher.rb +4 -4
- data/lib/rspec/benchmark/configuration.rb +8 -0
- data/lib/rspec/benchmark/formatter.rb +51 -0
- data/lib/rspec/benchmark/iteration_matcher.rb +18 -5
- data/lib/rspec/benchmark/matchers.rb +16 -16
- data/lib/rspec/benchmark/timing_matcher.rb +13 -13
- data/lib/rspec/benchmark/version.rb +1 -1
- metadata +21 -66
- data/Rakefile +0 -10
- data/lib/rspec/benchmark/format_time.rb +0 -29
- data/rspec-benchmark.gemspec +0 -37
- data/spec/spec_helper.rb +0 -37
- data/spec/unit/comparison_matcher_spec.rb +0 -212
- data/spec/unit/composable_spec.rb +0 -9
- data/spec/unit/configuration_spec.rb +0 -84
- data/spec/unit/format_time_spec.rb +0 -21
- data/spec/unit/perform_allocation_spec.rb +0 -128
- data/spec/unit/perform_at_least_spec.rb +0 -45
- data/spec/unit/perform_constant_spec.rb +0 -46
- data/spec/unit/perform_exponential_spec.rb +0 -42
- data/spec/unit/perform_linear_spec.rb +0 -80
- data/spec/unit/perform_logarithmic_spec.rb +0 -49
- data/spec/unit/perform_power_spec.rb +0 -55
- data/spec/unit/perform_under_spec.rb +0 -74
- data/tasks/coverage.rake +0 -11
- data/tasks/spec.rake +0 -34
@@ -1,49 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe 'RSpec::Benchmark::ComplexityMatcher', '#perform_logarithmic' do
|
4
|
-
# Iterated logarithm
|
5
|
-
# https://en.wikipedia.org/wiki/Iterated_logarithm
|
6
|
-
def log_star(n, repeat = 0)
|
7
|
-
n <= 1 ? repeat : 1 + log_star(Math.log(n), repeat += 1)
|
8
|
-
end
|
9
|
-
|
10
|
-
it "propagates error inside expectation" do
|
11
|
-
expect {
|
12
|
-
expect { raise 'boom' }.to perform_logarithmic
|
13
|
-
}.to raise_error(StandardError, /boom/)
|
14
|
-
end
|
15
|
-
|
16
|
-
context "expect { ... }.to perfom_logarithmic" do
|
17
|
-
xit "passes if the block performs logarithmic" do
|
18
|
-
range = bench_range(1, 8 << 18, ratio: 2)
|
19
|
-
numbers = range.map { |n| (1..n).to_a }
|
20
|
-
|
21
|
-
expect { |n, i|
|
22
|
-
numbers[i].bsearch { |x| x == 1 }
|
23
|
-
}.to perform_log.in_range(range[0], range[-1]).ratio(2).sample(100).times
|
24
|
-
end
|
25
|
-
|
26
|
-
it "fails if the block doesn't perform logarithmic" do
|
27
|
-
expect {
|
28
|
-
expect { |n| n }.to perform_logarithmic.in_range(1, 10_000).sample(100)
|
29
|
-
}.to raise_error("expected block to perform logarithmic, but performed constant")
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
context "expect { ... }.not_to perfom_logarithmic" do
|
34
|
-
it "passes if the block does not perform logarithmic" do
|
35
|
-
expect { |n| n }.not_to perform_logarithmic.in_range(1, 10_000).sample(100)
|
36
|
-
end
|
37
|
-
|
38
|
-
xit "fails if the block doesn't perform logarithmic" do
|
39
|
-
range = bench_range(1, 8 << 18, ratio: 2)
|
40
|
-
numbers = range.map { |n| (1..n).to_a }
|
41
|
-
|
42
|
-
expect {
|
43
|
-
expect { |n, i|
|
44
|
-
numbers[i].bsearch { |x| x == 1 }
|
45
|
-
}.not_to perform_log.in_range(range[0], range[-1]).ratio(2).sample(100).times
|
46
|
-
}.to raise_error("expected block not to perform logarithmic, but performed logarithmic")
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe 'RSpec::Benchmark::ComplexityMatcher', '#perform_power' do
|
4
|
-
def prefix_avg(numbers)
|
5
|
-
result = []
|
6
|
-
numbers.each_with_index do |i, num|
|
7
|
-
sum = 0.0
|
8
|
-
numbers[0..i].each do |a|
|
9
|
-
sum += a
|
10
|
-
end
|
11
|
-
result[i] = sum / i
|
12
|
-
end
|
13
|
-
result
|
14
|
-
end
|
15
|
-
|
16
|
-
it "propagates error inside expectation" do
|
17
|
-
expect {
|
18
|
-
expect { raise 'boom' }.to perform_power
|
19
|
-
}.to raise_error(StandardError, /boom/)
|
20
|
-
end
|
21
|
-
|
22
|
-
context "expect { ... }.to perfom_power" do
|
23
|
-
it "passes if the block performs power" do
|
24
|
-
range = bench_range(10, 8 << 5)
|
25
|
-
numbers = range.map { |n| Array.new(n) { rand(n) } }
|
26
|
-
|
27
|
-
expect { |n, i|
|
28
|
-
prefix_avg(numbers[i])
|
29
|
-
}.to perform_power.in_range(range[0], range[-1]).sample(100).times
|
30
|
-
end
|
31
|
-
|
32
|
-
it "fails if the block doesn't perform power" do
|
33
|
-
expect {
|
34
|
-
expect { |n| n }.to perform_power.in_range(1, 10_000).sample(100)
|
35
|
-
}.to raise_error("expected block to perform power, but performed constant")
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
context "expect { ... }.not_to perfom_power" do
|
40
|
-
it "passes if the block does not perform power" do
|
41
|
-
expect { |n| n }.not_to perform_power.in_range(1, 10_000).sample(100)
|
42
|
-
end
|
43
|
-
|
44
|
-
it "fails if the block doesn't perform power" do
|
45
|
-
range = bench_range(10, 8 << 5)
|
46
|
-
numbers = range.map { |n| Array.new(n) { rand(n) } }
|
47
|
-
|
48
|
-
expect {
|
49
|
-
expect { |n, i|
|
50
|
-
prefix_avg(numbers[i])
|
51
|
-
}.not_to perform_power.in_range(range[0], range[-1]).sample(100).times
|
52
|
-
}.to raise_error("expected block not to perform power, but performed power")
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
@@ -1,74 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe 'RSpec::Benchmark::TimingMatcher', '#perform_under' do
|
4
|
-
it "propagates error inside expectation" do
|
5
|
-
expect {
|
6
|
-
expect { raise 'boom' }.to perform_under(0.01).sec
|
7
|
-
}.to raise_error(StandardError, /boom/)
|
8
|
-
end
|
9
|
-
|
10
|
-
it "allows to configure warmup cycles" do
|
11
|
-
bench = [0.005, 0.00001]
|
12
|
-
allow(::Benchmark::Perf::ExecutionTime).to receive(:run).and_return(bench)
|
13
|
-
|
14
|
-
expect { 'x' * 1024 * 10 }.to perform_under(0.006).sec.warmup(2).times.sample(3)
|
15
|
-
|
16
|
-
expect(::Benchmark::Perf::ExecutionTime).to have_received(:run).with(
|
17
|
-
subprocess: false, repeat: 3, warmup: 2)
|
18
|
-
end
|
19
|
-
|
20
|
-
it "doesn't allow sample size less than 1" do
|
21
|
-
expect {
|
22
|
-
expect { 'x' * 1024 * 10 }.to perform_under(0.006).sec.sample(0)
|
23
|
-
}.to raise_error(/Repeat value: 0 needs to be greater than 0/)
|
24
|
-
end
|
25
|
-
|
26
|
-
context "expect { ... }.to perfom_under(...).sample" do
|
27
|
-
it "passes if the block performs under threshold" do
|
28
|
-
expect {
|
29
|
-
'x' * 1024 * 10
|
30
|
-
}.to perform_under(0.006).sec.sample(10).times
|
31
|
-
end
|
32
|
-
|
33
|
-
it "fails if the block performs above threshold" do
|
34
|
-
expect {
|
35
|
-
expect {
|
36
|
-
'x' * 1024 * 1024 * 100
|
37
|
-
}.to perform_under(0.0001).sample(5)
|
38
|
-
}.to raise_error(/expected block to perform under 100 μs, but performed above \d+(\.\d+)? ([μmn]s|sec) \(± \d+(\.\d+)? ([μmn]s|sec)\)/)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
context "expect { ... }.not_to perform_under(...).sample" do
|
43
|
-
it "passes if the block does not perform under threshold" do
|
44
|
-
expect {
|
45
|
-
'x' * 1024 * 1024 * 10
|
46
|
-
}.to_not perform_under(0.001).sample(2)
|
47
|
-
end
|
48
|
-
|
49
|
-
it "fails if the block perfoms under threshold" do
|
50
|
-
expect {
|
51
|
-
expect {
|
52
|
-
'x' * 1024 * 1024 * 10
|
53
|
-
}.to_not perform_under(1).sample(2)
|
54
|
-
}.to raise_error(/expected block to not perform under 1 sec, but performed \d+(\.\d+)? ([μmn]s|sec) \(± \d+(\.\d+)? ([μmn]s|sec)\) under/)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
context 'threshold conversions' do
|
59
|
-
it "converts 1ms to sec" do
|
60
|
-
matcher = perform_under(1).ms
|
61
|
-
expect(matcher.threshold).to eq(0.001)
|
62
|
-
end
|
63
|
-
|
64
|
-
it "converts 1000us to sec" do
|
65
|
-
matcher = perform_under(1000).us
|
66
|
-
expect(matcher.threshold).to eq(0.001)
|
67
|
-
end
|
68
|
-
|
69
|
-
it "converts ns to sec" do
|
70
|
-
matcher = perform_under(100_000).ns
|
71
|
-
expect(matcher.threshold).to eq(0.0001)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
data/tasks/coverage.rake
DELETED
data/tasks/spec.rake
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
begin
|
4
|
-
require 'rspec/core/rake_task'
|
5
|
-
|
6
|
-
desc 'Run all specs'
|
7
|
-
RSpec::Core::RakeTask.new(:spec) do |task|
|
8
|
-
task.pattern = 'spec/{unit,integration}{,/*/**}/*_spec.rb'
|
9
|
-
end
|
10
|
-
|
11
|
-
namespace :spec do
|
12
|
-
desc 'Run unit specs'
|
13
|
-
RSpec::Core::RakeTask.new(:unit) do |task|
|
14
|
-
task.pattern = 'spec/unit{,/*/**}/*_spec.rb'
|
15
|
-
end
|
16
|
-
|
17
|
-
desc 'Run integration specs'
|
18
|
-
RSpec::Core::RakeTask.new(:integration) do |task|
|
19
|
-
task.pattern = 'spec/integration{,/*/**}/*_spec.rb'
|
20
|
-
end
|
21
|
-
|
22
|
-
desc 'Run performance specs'
|
23
|
-
RSpec::Core::RakeTask.new(:perf) do |task|
|
24
|
-
task.pattern = 'spec/performance{,/*/**}/*_spec.rb'
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
rescue LoadError
|
29
|
-
%w[spec spec:unit spec:integration spec:perf].each do |name|
|
30
|
-
task name do
|
31
|
-
$stderr.puts "In order to run #{name}, do `gem install rspec`"
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|