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.
@@ -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
@@ -1,11 +0,0 @@
1
- # encoding: utf-8
2
-
3
- desc 'Measure code coverage'
4
- task :coverage do
5
- begin
6
- original, ENV['COVERAGE'] = ENV['COVERAGE'], 'true'
7
- Rake::Task['spec'].invoke
8
- ensure
9
- ENV['COVERAGE'] = original
10
- end
11
- end
@@ -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