rspec-benchmark 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 798bc5d4e03d43057fe769a612d69c7b9e94c1d6cf00cb119ff343f184c2dcc2
4
- data.tar.gz: 437e723c5984d44d2af9e24dc2eab5a952d4be2531f86d1e5a67de6edfcd122c
3
+ metadata.gz: 5d86ffbdf2e75f6789264a4206e3caf39f32927f5ad751eb6f02b69fc72743dc
4
+ data.tar.gz: '096f74a7d6ac5b64b347c38f19757ddd7b870e9dc80996e2dcb09ad13bdacfe2'
5
5
  SHA512:
6
- metadata.gz: 48a31057edbf78fc8f535110e9a99ccc1bf7a3f7e2ce044eb99cfb3dd1322fe75ce00996acec8b5759b15e9622ef39b6b5cfa4fb678055dda0a8cfd943d1e1cf
7
- data.tar.gz: 755534b8baf828aad86a8659bd59c123a2056a3f8b169699db0de5e19468476637f83c093fbd12a1db153c24a29039dacbecd648c67aba7df351b4f15906c492
6
+ metadata.gz: 673740a08e95e8d0790a9200e30400bb0f2fc0b1ec5f12a4665b709363f0687af9a35a767b336d24aba13d21b25fea334e68011d8572b8c2a0de9e90e845c3e3
7
+ data.tar.gz: e5a4fd2ffa45d39980edfd900d385f8df95083ef7d6741cea8fc1a885ce34008feec1d13ad602123861f07acb8a5b1fb1fe1f41f12b150cfe037c2d6aa2e5ffe
@@ -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
- # @return [Boolean]
182
+ # At most comparison
183
+ #
183
184
  # @example
184
- # @actual = 40
185
- # @count = 41
185
+ # @ratio = 3
186
+ # @count = 4
186
187
  # perform_faster_than { ... }.at_most(@count).times # => true
187
188
  #
188
- # @actual = 40
189
- # @count = 41
189
+ # @ratio = 3
190
+ # @count = 2
190
191
  # perform_faster_than { ... }.at_most(@count).times # => false
191
192
  #
192
- # @actual = 1/40
193
- # @count = 41
193
+ # @ratio = 1/4
194
+ # @count = 5
194
195
  # perform_slower_than { ... }.at_most(@count).times # => true
195
196
  #
196
- # @actual = 1/40
197
- # @count = 41
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
- # @actual = 40.1
213
- # @count = 40
216
+ # @ratio = 3.5
217
+ # @count = 3
214
218
  # perform_faster_than { ... }.exact(@count).times # => true
215
219
  #
216
- # @actual = 40.1
217
- # @count = 41
218
- # perform_faster_than { ... }.exact(@count).times # => true
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
- @count == @ratio.round
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
- # @return [Boolean]
235
+ # At least comparison, meaning more than expected count
236
+ #
228
237
  # @example
229
- # @actual = 41
230
- # @count = 40
238
+ # @ratio = 4
239
+ # @count = 3
231
240
  # perform_faster_than { ... } # => true
232
241
  #
233
- # @actual = 41
234
- # @count = 40
242
+ # @ratio = 4
243
+ # @count = 3
235
244
  # perform_faster_than { ... }.at_least(@count).times # => true
236
245
  #
237
- # @actual = 1/40
238
- # @count = 41
246
+ # @ratio = 1/4
247
+ # @count = 3
239
248
  # perform_slower_than { ... }.at_least(@count).times # => false
240
249
  #
241
- # @actual = 1/41
242
- # @count = 40
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 / @count > 1
259
+ @ratio > @count
248
260
  else
249
- @ratio / @count < 1 / @count.to_f
261
+ @ratio < (1.0 / @count)
250
262
  end
251
263
  end
252
264
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RSpec
4
4
  module Benchmark
5
- VERSION = "0.5.0"
5
+ VERSION = "0.5.1"
6
6
  end # Benchmark
7
7
  end # RSpec
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
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(20).times
170
+ }.to perform_slower_than { 1 << 1 }.at_least(15).times
171
171
  end
172
172
 
173
- it "fails if the block does performs faster than sample" do
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.0
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-04-21 00:00:00.000000000 Z
11
+ date: 2019-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: benchmark-malloc