rspec-benchmark 0.5.0 → 0.5.1
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 +6 -0
- data/lib/rspec/benchmark/comparison_matcher.rb +38 -26
- data/lib/rspec/benchmark/version.rb +1 -1
- data/spec/unit/comparison_matcher_spec.rb +11 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d86ffbdf2e75f6789264a4206e3caf39f32927f5ad751eb6f02b69fc72743dc
|
4
|
+
data.tar.gz: '096f74a7d6ac5b64b347c38f19757ddd7b870e9dc80996e2dcb09ad13bdacfe2'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 673740a08e95e8d0790a9200e30400bb0f2fc0b1ec5f12a4665b709363f0687af9a35a767b336d24aba13d21b25fea334e68011d8572b8c2a0de9e90e845c3e3
|
7
|
+
data.tar.gz: e5a4fd2ffa45d39980edfd900d385f8df95083ef7d6741cea8fc1a885ce34008feec1d13ad602123861f07acb8a5b1fb1fe1f41f12b150cfe037c2d6aa2e5ffe
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Change log
|
2
2
|
|
3
|
+
## [v0.5.1] - 2019-09-11
|
4
|
+
|
5
|
+
### Fixed
|
6
|
+
* Fix perform_slower_than matcher the at_least & exact comparisons
|
7
|
+
|
3
8
|
## [v0.5.0] - 2019-04-21
|
4
9
|
|
5
10
|
## Added
|
@@ -49,6 +54,7 @@
|
|
49
54
|
|
50
55
|
Initial release
|
51
56
|
|
57
|
+
[v0.5.1]: https://github.com/peter-murach/rspec-benchmark/compare/v0.5.0...v0.5.1
|
52
58
|
[v0.5.0]: https://github.com/peter-murach/rspec-benchmark/compare/v0.4.0...v0.5.0
|
53
59
|
[v0.4.0]: https://github.com/peter-murach/rspec-benchmark/compare/v0.3.0...v0.4.0
|
54
60
|
[v0.3.0]: https://github.com/peter-murach/rspec-benchmark/compare/v0.2.0...v0.3.0
|
@@ -179,23 +179,27 @@ module RSpec
|
|
179
179
|
@count = convert_count(n)
|
180
180
|
end
|
181
181
|
|
182
|
-
#
|
182
|
+
# At most comparison
|
183
|
+
#
|
183
184
|
# @example
|
184
|
-
# @
|
185
|
-
# @count =
|
185
|
+
# @ratio = 3
|
186
|
+
# @count = 4
|
186
187
|
# perform_faster_than { ... }.at_most(@count).times # => true
|
187
188
|
#
|
188
|
-
# @
|
189
|
-
# @count =
|
189
|
+
# @ratio = 3
|
190
|
+
# @count = 2
|
190
191
|
# perform_faster_than { ... }.at_most(@count).times # => false
|
191
192
|
#
|
192
|
-
# @
|
193
|
-
# @count =
|
193
|
+
# @ratio = 1/4
|
194
|
+
# @count = 5
|
194
195
|
# perform_slower_than { ... }.at_most(@count).times # => true
|
195
196
|
#
|
196
|
-
# @
|
197
|
-
# @count =
|
197
|
+
# @ratio = 1/4
|
198
|
+
# @count = 3
|
198
199
|
# perform_slower_than { ... }.at_most(@count).times # => false
|
200
|
+
#
|
201
|
+
# @return [Boolean]
|
202
|
+
#
|
199
203
|
# @api private
|
200
204
|
def at_most_comparison
|
201
205
|
if @comparison_type == :faster
|
@@ -209,44 +213,52 @@ module RSpec
|
|
209
213
|
# exactly number of counts.
|
210
214
|
#
|
211
215
|
# @example
|
212
|
-
# @
|
213
|
-
# @count =
|
216
|
+
# @ratio = 3.5
|
217
|
+
# @count = 3
|
214
218
|
# perform_faster_than { ... }.exact(@count).times # => true
|
215
219
|
#
|
216
|
-
# @
|
217
|
-
# @count =
|
218
|
-
#
|
220
|
+
# @ratio = 1/4
|
221
|
+
# @count = 4
|
222
|
+
# perform_slower_than { ... }.exact(@count).times # => true
|
219
223
|
#
|
220
224
|
# @return [Boolean]
|
221
225
|
#
|
222
226
|
# @api private
|
223
227
|
def exact_comparison
|
224
|
-
@
|
228
|
+
if @comparison_type == :faster
|
229
|
+
@count == @ratio.round
|
230
|
+
else
|
231
|
+
@count == (1.0 / @ratio).round
|
232
|
+
end
|
225
233
|
end
|
226
234
|
|
227
|
-
#
|
235
|
+
# At least comparison, meaning more than expected count
|
236
|
+
#
|
228
237
|
# @example
|
229
|
-
# @
|
230
|
-
# @count =
|
238
|
+
# @ratio = 4
|
239
|
+
# @count = 3
|
231
240
|
# perform_faster_than { ... } # => true
|
232
241
|
#
|
233
|
-
# @
|
234
|
-
# @count =
|
242
|
+
# @ratio = 4
|
243
|
+
# @count = 3
|
235
244
|
# perform_faster_than { ... }.at_least(@count).times # => true
|
236
245
|
#
|
237
|
-
# @
|
238
|
-
# @count =
|
246
|
+
# @ratio = 1/4
|
247
|
+
# @count = 3
|
239
248
|
# perform_slower_than { ... }.at_least(@count).times # => false
|
240
249
|
#
|
241
|
-
# @
|
242
|
-
# @count =
|
250
|
+
# @ratio = 1/3
|
251
|
+
# @count = 4
|
243
252
|
# perform_slower_than { ... }.at_least(@count).times # => true
|
253
|
+
#
|
254
|
+
# @return [Boolean]
|
255
|
+
#
|
244
256
|
# @api private
|
245
257
|
def default_comparison
|
246
258
|
if @comparison_type == :faster
|
247
|
-
@ratio
|
259
|
+
@ratio > @count
|
248
260
|
else
|
249
|
-
@ratio
|
261
|
+
@ratio < (1.0 / @count)
|
250
262
|
end
|
251
263
|
end
|
252
264
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
RSpec.describe RSpec::Benchmark::ComparisonMatcher::Matcher do
|
4
4
|
|
@@ -167,10 +167,18 @@ RSpec.describe RSpec::Benchmark::ComparisonMatcher::Matcher do
|
|
167
167
|
it "passes if the block does performs slower than sample" do
|
168
168
|
expect {
|
169
169
|
'x' * 10 * 1024
|
170
|
-
}.to perform_slower_than { 1 << 1 }.at_least(
|
170
|
+
}.to perform_slower_than { 1 << 1 }.at_least(15).times
|
171
171
|
end
|
172
172
|
|
173
|
-
it "fails if the block
|
173
|
+
it "fails if the block count compared with sample is too high" do
|
174
|
+
expect {
|
175
|
+
expect {
|
176
|
+
'x' * 10 * 1024
|
177
|
+
}.to perform_slower_than { 1 << 1 }.at_least(200).times
|
178
|
+
}.to raise_error(/expected given block to perform slower than comparison block by at_least 200 times, but performed slower by \d+.\d+ time/)
|
179
|
+
end
|
180
|
+
|
181
|
+
it "fails if the block does perform faster than sample" do
|
174
182
|
expect {
|
175
183
|
expect {
|
176
184
|
1 << 1
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-benchmark
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Murach
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-09-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: benchmark-malloc
|