radius-spec 0.5.0 → 0.9.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/.github/workflows/ci.yml +28 -0
- data/.github/workflows/reviewdog.yml +21 -0
- data/.rubocop.yml +9 -5
- data/CHANGELOG.md +98 -0
- data/Gemfile +2 -3
- data/README.md +5 -6
- data/benchmarks/call_vs_yield.rb +33 -2
- data/benchmarks/casecmp_vs_downcase.rb +488 -0
- data/benchmarks/cover_vs_include.rb +2 -2
- data/benchmarks/format_string.rb +3 -3
- data/benchmarks/hash_each.rb +305 -0
- data/benchmarks/hash_merge.rb +1 -1
- data/benchmarks/hash_transform.rb +455 -0
- data/benchmarks/style_hash_like_case.rb +285 -0
- data/benchmarks/unfreeze_string.rb +0 -2
- data/bin/ci +1 -1
- data/common_rubocop.yml +166 -45
- data/common_rubocop_rails.yml +47 -20
- data/lib/radius/spec/model_factory.rb +0 -2
- data/lib/radius/spec/rspec.rb +9 -0
- data/lib/radius/spec/vcr.rb +0 -2
- data/lib/radius/spec/version.rb +1 -1
- data/radius-spec.gemspec +8 -7
- metadata +42 -19
- data/.travis.yml +0 -17
- data/bin/ci-code-review +0 -28
@@ -0,0 +1,488 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Run from the command line: bundle exec ruby benchmarks/casecmp_vs_downcase.rb
|
4
|
+
require_relative 'bm_setup'
|
5
|
+
|
6
|
+
display_benchmark_header
|
7
|
+
|
8
|
+
EXPECTED = "match"
|
9
|
+
|
10
|
+
puts "### Base Cases"
|
11
|
+
|
12
|
+
def downcase_eql(test_case)
|
13
|
+
EXPECTED == test_case.downcase
|
14
|
+
end
|
15
|
+
|
16
|
+
def casecmp_eql(test_case)
|
17
|
+
0 == EXPECTED.casecmp(test_case)
|
18
|
+
end
|
19
|
+
|
20
|
+
def casecmp_zero(test_case)
|
21
|
+
EXPECTED.casecmp(test_case).zero?
|
22
|
+
end
|
23
|
+
|
24
|
+
# This is similar to the original Rubocop cited benchmark code.
|
25
|
+
["No MaTcH", "MaTcH"].each do |test_case|
|
26
|
+
section "Case: #{test_case.downcase}" do |bench|
|
27
|
+
bench.report("== downcase") do
|
28
|
+
downcase_eql(test_case)
|
29
|
+
end
|
30
|
+
|
31
|
+
bench.report("== casecmp") do
|
32
|
+
casecmp_eql(test_case)
|
33
|
+
end
|
34
|
+
|
35
|
+
bench.report("casecmp.zero?") do
|
36
|
+
casecmp_zero(test_case)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# As of Ruby 2.5 both `casecmp` and `casecmp?` accept any object. In the cases
|
42
|
+
# where the object is not a string they return `nil`. Prior Ruby 2.5 string
|
43
|
+
# conversions need to occur before the compare.
|
44
|
+
puts "### Type Cases"
|
45
|
+
|
46
|
+
def tos_downcase_eql(test_case)
|
47
|
+
EXPECTED == test_case.to_s.downcase
|
48
|
+
end
|
49
|
+
|
50
|
+
def safe_casecmp_zero(test_case)
|
51
|
+
EXPECTED.casecmp(test_case)&.zero?
|
52
|
+
end
|
53
|
+
|
54
|
+
def casecmp_to_i_zero(test_case)
|
55
|
+
EXPECTED.casecmp(test_case).to_i.zero?
|
56
|
+
end
|
57
|
+
|
58
|
+
def casecmp?(test_case)
|
59
|
+
EXPECTED.casecmp?(test_case)
|
60
|
+
end
|
61
|
+
|
62
|
+
class StringLike
|
63
|
+
def initialize(test_case)
|
64
|
+
@test_case = test_case
|
65
|
+
end
|
66
|
+
|
67
|
+
def to_str
|
68
|
+
@test_case
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
[
|
73
|
+
nil,
|
74
|
+
"no match",
|
75
|
+
"match",
|
76
|
+
123,
|
77
|
+
Object.new,
|
78
|
+
StringLike.new("no match"),
|
79
|
+
StringLike.new("match"),
|
80
|
+
].each do |test_case|
|
81
|
+
section "Type Case: #{test_case.inspect}" do |bench|
|
82
|
+
bench.report("== to_s.downcase") do
|
83
|
+
tos_downcase_eql(test_case)
|
84
|
+
end
|
85
|
+
|
86
|
+
bench.report("== casecmp") do
|
87
|
+
casecmp_eql(test_case)
|
88
|
+
end
|
89
|
+
|
90
|
+
bench.report("casecmp.zero?") do
|
91
|
+
safe_casecmp_zero(test_case)
|
92
|
+
end
|
93
|
+
|
94
|
+
bench.report("casecmp.to_i.zero?") do
|
95
|
+
casecmp_to_i_zero(test_case)
|
96
|
+
end
|
97
|
+
|
98
|
+
bench.report("casecmp?") do
|
99
|
+
casecmp?(test_case)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def pre_casecmp_eql(test_case)
|
105
|
+
test_case && 0 == EXPECTED.casecmp(test_case)
|
106
|
+
end
|
107
|
+
|
108
|
+
def pre_casecmp_zero(test_case)
|
109
|
+
test_case && EXPECTED.casecmp(test_case).zero?
|
110
|
+
end
|
111
|
+
|
112
|
+
def pre_bang_casecmp_eql(test_case)
|
113
|
+
!!test_case && 0 == EXPECTED.casecmp(test_case)
|
114
|
+
end
|
115
|
+
|
116
|
+
def pre_bang_casecmp_zero(test_case)
|
117
|
+
!!test_case && EXPECTED.casecmp(test_case).zero?
|
118
|
+
end
|
119
|
+
|
120
|
+
def pre_nil_casecmp_eql(test_case)
|
121
|
+
!test_case.nil? && 0 == EXPECTED.casecmp(test_case)
|
122
|
+
end
|
123
|
+
|
124
|
+
def pre_nil_casecmp_zero(test_case)
|
125
|
+
!test_case.nil? && EXPECTED.casecmp(test_case).zero?
|
126
|
+
end
|
127
|
+
|
128
|
+
# Given the results below this is another set of tests to try to determine if
|
129
|
+
# knowing you'll either have `nil` or a `String`
|
130
|
+
[nil, "no match"].each do |test_case|
|
131
|
+
section "Pre-check Case: #{test_case.inspect}" do |bench|
|
132
|
+
bench.report("== casecmp(to_s)") do
|
133
|
+
casecmp_eql(test_case.to_s)
|
134
|
+
end
|
135
|
+
|
136
|
+
if RUBY_VERSION.to_f > 2.3
|
137
|
+
bench.report("casecmp?(to_s)") do
|
138
|
+
casecmp?(test_case.to_s)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
if RUBY_VERSION.to_f > 2.4
|
143
|
+
bench.report("casecmp?") do
|
144
|
+
casecmp?(test_case)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
bench.report("falsey casecmp.zero?") do
|
149
|
+
pre_casecmp_zero(test_case)
|
150
|
+
end
|
151
|
+
|
152
|
+
bench.report("falsey == casecmp") do
|
153
|
+
pre_casecmp_eql(test_case)
|
154
|
+
end
|
155
|
+
|
156
|
+
bench.report("!! casecmp.zero?") do
|
157
|
+
pre_bang_casecmp_zero(test_case)
|
158
|
+
end
|
159
|
+
|
160
|
+
bench.report("!! == casecmp") do
|
161
|
+
pre_bang_casecmp_eql(test_case)
|
162
|
+
end
|
163
|
+
|
164
|
+
bench.report("nil? casecmp.zero?") do
|
165
|
+
pre_nil_casecmp_zero(test_case)
|
166
|
+
end
|
167
|
+
|
168
|
+
bench.report("nil? == casecmp") do
|
169
|
+
pre_nil_casecmp_eql(test_case)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
__END__
|
175
|
+
|
176
|
+
These results were a little surprising. With `casecmp?` being implemented in C
|
177
|
+
I fully expected that to be the fastest version. As the results below show, it
|
178
|
+
was actually the slowest except for the `nil` case. Given both `casecmp` and
|
179
|
+
`casecmp?` need to perform the same type coercions in Ruby 2.5 this is still
|
180
|
+
a bit of a mystery to me.
|
181
|
+
|
182
|
+
### Environment
|
183
|
+
|
184
|
+
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin16]
|
185
|
+
GC Disabled: false
|
186
|
+
|
187
|
+
### Test Cases
|
188
|
+
|
189
|
+
### Base Cases
|
190
|
+
|
191
|
+
#### Case: no match
|
192
|
+
|
193
|
+
```
|
194
|
+
Warming up --------------------------------------
|
195
|
+
== downcase 212.956k i/100ms
|
196
|
+
== casecmp 242.441k i/100ms
|
197
|
+
casecmp.zero? 250.362k i/100ms
|
198
|
+
Calculating -------------------------------------
|
199
|
+
== downcase 5.758M (± 1.1%) i/s - 28.749M in 5.013717s
|
200
|
+
== casecmp 7.263M (± 0.8%) i/s - 36.366M in 5.018952s
|
201
|
+
casecmp.zero? 6.641M (± 0.9%) i/s - 33.298M in 5.026902s
|
202
|
+
with 95.0% confidence
|
203
|
+
|
204
|
+
Comparison:
|
205
|
+
== casecmp: 7262964.1 i/s
|
206
|
+
casecmp.zero?: 6640838.5 i/s - 1.09x (± 0.01) slower
|
207
|
+
== downcase: 5757879.1 i/s - 1.26x (± 0.02) slower
|
208
|
+
with 95.0% confidence
|
209
|
+
```
|
210
|
+
|
211
|
+
#### Case: match
|
212
|
+
|
213
|
+
```
|
214
|
+
Warming up --------------------------------------
|
215
|
+
== downcase 223.277k i/100ms
|
216
|
+
== casecmp 255.309k i/100ms
|
217
|
+
casecmp.zero? 244.326k i/100ms
|
218
|
+
Calculating -------------------------------------
|
219
|
+
== downcase 5.601M (± 0.7%) i/s - 28.133M in 5.031201s
|
220
|
+
== casecmp 7.069M (± 0.9%) i/s - 35.488M in 5.033449s
|
221
|
+
casecmp.zero? 6.514M (± 1.0%) i/s - 32.495M in 5.007338s
|
222
|
+
with 95.0% confidence
|
223
|
+
|
224
|
+
Comparison:
|
225
|
+
== casecmp: 7069433.4 i/s
|
226
|
+
casecmp.zero?: 6513865.5 i/s - 1.09x (± 0.01) slower
|
227
|
+
== downcase: 5600607.7 i/s - 1.26x (± 0.01) slower
|
228
|
+
with 95.0% confidence
|
229
|
+
```
|
230
|
+
### Type Cases
|
231
|
+
|
232
|
+
#### Type Case: nil
|
233
|
+
|
234
|
+
```
|
235
|
+
Warming up --------------------------------------
|
236
|
+
== to_s.downcase 206.757k i/100ms
|
237
|
+
== casecmp 165.652k i/100ms
|
238
|
+
casecmp.zero? 243.968k i/100ms
|
239
|
+
casecmp.to_i.zero? 228.771k i/100ms
|
240
|
+
casecmp? 245.631k i/100ms
|
241
|
+
Calculating -------------------------------------
|
242
|
+
== to_s.downcase 4.457M (± 1.3%) i/s - 22.330M in 5.036046s
|
243
|
+
== casecmp 2.959M (± 0.9%) i/s - 14.909M in 5.048155s
|
244
|
+
casecmp.zero? 6.571M (± 0.8%) i/s - 32.936M in 5.023643s
|
245
|
+
casecmp.to_i.zero? 5.610M (± 1.0%) i/s - 28.139M in 5.030920s
|
246
|
+
casecmp? 6.426M (± 0.9%) i/s - 32.178M in 5.022549s
|
247
|
+
with 95.0% confidence
|
248
|
+
|
249
|
+
Comparison:
|
250
|
+
casecmp.zero?: 6570981.1 i/s
|
251
|
+
casecmp?: 6426432.5 i/s - 1.02x (± 0.01) slower
|
252
|
+
casecmp.to_i.zero?: 5609983.7 i/s - 1.17x (± 0.02) slower
|
253
|
+
== to_s.downcase: 4457210.7 i/s - 1.47x (± 0.02) slower
|
254
|
+
== casecmp: 2959310.9 i/s - 2.22x (± 0.03) slower
|
255
|
+
with 95.0% confidence
|
256
|
+
```
|
257
|
+
|
258
|
+
#### Type Case: "no match"
|
259
|
+
|
260
|
+
```
|
261
|
+
Warming up --------------------------------------
|
262
|
+
== to_s.downcase 224.166k i/100ms
|
263
|
+
== casecmp 255.225k i/100ms
|
264
|
+
casecmp.zero? 244.858k i/100ms
|
265
|
+
casecmp.to_i.zero? 239.323k i/100ms
|
266
|
+
casecmp? 184.603k i/100ms
|
267
|
+
Calculating -------------------------------------
|
268
|
+
== to_s.downcase 4.986M (± 1.7%) i/s - 24.882M in 5.041514s
|
269
|
+
== casecmp 7.478M (± 0.9%) i/s - 37.518M in 5.033271s
|
270
|
+
casecmp.zero? 6.879M (± 1.0%) i/s - 34.525M in 5.036217s
|
271
|
+
casecmp.to_i.zero? 6.166M (± 0.9%) i/s - 30.873M in 5.021792s
|
272
|
+
casecmp? 4.520M (± 1.5%) i/s - 22.522M in 5.022920s
|
273
|
+
with 95.0% confidence
|
274
|
+
|
275
|
+
Comparison:
|
276
|
+
== casecmp: 7478045.4 i/s
|
277
|
+
casecmp.zero?: 6878660.6 i/s - 1.09x (± 0.01) slower
|
278
|
+
casecmp.to_i.zero?: 6166061.6 i/s - 1.21x (± 0.02) slower
|
279
|
+
== to_s.downcase: 4985671.0 i/s - 1.50x (± 0.03) slower
|
280
|
+
casecmp?: 4520190.0 i/s - 1.65x (± 0.03) slower
|
281
|
+
with 95.0% confidence
|
282
|
+
```
|
283
|
+
|
284
|
+
#### Type Case: "match"
|
285
|
+
|
286
|
+
```
|
287
|
+
Warming up --------------------------------------
|
288
|
+
== to_s.downcase 222.165k i/100ms
|
289
|
+
== casecmp 255.637k i/100ms
|
290
|
+
casecmp.zero? 242.725k i/100ms
|
291
|
+
casecmp.to_i.zero? 234.070k i/100ms
|
292
|
+
casecmp? 196.526k i/100ms
|
293
|
+
Calculating -------------------------------------
|
294
|
+
== to_s.downcase 5.061M (± 1.1%) i/s - 25.327M in 5.022350s
|
295
|
+
== casecmp 7.213M (± 0.8%) i/s - 36.045M in 5.009733s
|
296
|
+
casecmp.zero? 6.591M (± 0.9%) i/s - 33.011M in 5.021453s
|
297
|
+
casecmp.to_i.zero? 5.916M (± 0.9%) i/s - 29.727M in 5.039360s
|
298
|
+
casecmp? 4.462M (± 1.2%) i/s - 22.404M in 5.041505s
|
299
|
+
with 95.0% confidence
|
300
|
+
|
301
|
+
Comparison:
|
302
|
+
== casecmp: 7212692.8 i/s
|
303
|
+
casecmp.zero?: 6590791.5 i/s - 1.09x (± 0.01) slower
|
304
|
+
casecmp.to_i.zero?: 5915576.8 i/s - 1.22x (± 0.02) slower
|
305
|
+
== to_s.downcase: 5060645.9 i/s - 1.43x (± 0.02) slower
|
306
|
+
casecmp?: 4462174.0 i/s - 1.62x (± 0.02) slower
|
307
|
+
with 95.0% confidence
|
308
|
+
```
|
309
|
+
|
310
|
+
#### Type Case: 123
|
311
|
+
|
312
|
+
```
|
313
|
+
Warming up --------------------------------------
|
314
|
+
== to_s.downcase 194.578k i/100ms
|
315
|
+
== casecmp 162.422k i/100ms
|
316
|
+
casecmp.zero? 241.653k i/100ms
|
317
|
+
casecmp.to_i.zero? 225.119k i/100ms
|
318
|
+
casecmp? 240.602k i/100ms
|
319
|
+
Calculating -------------------------------------
|
320
|
+
== to_s.downcase 4.099M (± 1.0%) i/s - 20.625M in 5.045741s
|
321
|
+
== casecmp 3.068M (± 1.1%) i/s - 15.430M in 5.044417s
|
322
|
+
casecmp.zero? 6.334M (± 0.8%) i/s - 31.657M in 5.007791s
|
323
|
+
casecmp.to_i.zero? 5.284M (± 1.6%) i/s - 26.339M in 5.031971s
|
324
|
+
casecmp? 6.478M (± 1.0%) i/s - 32.481M in 5.031290s
|
325
|
+
with 95.0% confidence
|
326
|
+
|
327
|
+
Comparison:
|
328
|
+
casecmp?: 6478253.4 i/s
|
329
|
+
casecmp.zero?: 6333577.2 i/s - 1.02x (± 0.01) slower
|
330
|
+
casecmp.to_i.zero?: 5284198.7 i/s - 1.23x (± 0.02) slower
|
331
|
+
== to_s.downcase: 4098628.0 i/s - 1.58x (± 0.02) slower
|
332
|
+
== casecmp: 3067817.5 i/s - 2.11x (± 0.03) slower
|
333
|
+
with 95.0% confidence
|
334
|
+
```
|
335
|
+
|
336
|
+
#### Type Case: #<Object:0x00007fcd219587b0>
|
337
|
+
|
338
|
+
```
|
339
|
+
Warming up --------------------------------------
|
340
|
+
== to_s.downcase 52.158k i/100ms
|
341
|
+
== casecmp 163.492k i/100ms
|
342
|
+
casecmp.zero? 240.188k i/100ms
|
343
|
+
casecmp.to_i.zero? 226.153k i/100ms
|
344
|
+
casecmp? 236.788k i/100ms
|
345
|
+
Calculating -------------------------------------
|
346
|
+
== to_s.downcase 640.939k (± 1.1%) i/s - 3.234M in 5.053840s
|
347
|
+
== casecmp 3.075M (± 0.9%) i/s - 15.368M in 5.008669s
|
348
|
+
casecmp.zero? 6.623M (± 0.9%) i/s - 33.146M in 5.020333s
|
349
|
+
casecmp.to_i.zero? 5.376M (± 1.2%) i/s - 26.912M in 5.027477s
|
350
|
+
casecmp? 6.726M (± 1.0%) i/s - 33.624M in 5.016239s
|
351
|
+
with 95.0% confidence
|
352
|
+
|
353
|
+
Comparison:
|
354
|
+
casecmp?: 6726445.6 i/s
|
355
|
+
casecmp.zero?: 6623328.3 i/s - same-ish: difference falls within error
|
356
|
+
casecmp.to_i.zero?: 5376386.8 i/s - 1.25x (± 0.02) slower
|
357
|
+
== casecmp: 3074731.3 i/s - 2.19x (± 0.03) slower
|
358
|
+
== to_s.downcase: 640938.7 i/s - 10.49x (± 0.15) slower
|
359
|
+
with 95.0% confidence
|
360
|
+
```
|
361
|
+
|
362
|
+
#### Type Case: #<StringLike:0x00007fcd21958788 @test_case="no match">
|
363
|
+
|
364
|
+
```
|
365
|
+
Warming up --------------------------------------
|
366
|
+
== to_s.downcase 52.238k i/100ms
|
367
|
+
== casecmp 212.362k i/100ms
|
368
|
+
casecmp.zero? 207.266k i/100ms
|
369
|
+
casecmp.to_i.zero? 203.147k i/100ms
|
370
|
+
casecmp? 179.658k i/100ms
|
371
|
+
Calculating -------------------------------------
|
372
|
+
== to_s.downcase 649.352k (± 0.9%) i/s - 3.291M in 5.074729s
|
373
|
+
== casecmp 5.069M (± 0.9%) i/s - 25.483M in 5.039082s
|
374
|
+
casecmp.zero? 4.852M (± 0.9%) i/s - 24.250M in 5.011911s
|
375
|
+
casecmp.to_i.zero? 4.395M (± 1.1%) i/s - 21.940M in 5.009899s
|
376
|
+
casecmp? 3.443M (± 1.3%) i/s - 17.247M in 5.028774s
|
377
|
+
with 95.0% confidence
|
378
|
+
|
379
|
+
Comparison:
|
380
|
+
== casecmp: 5068628.3 i/s
|
381
|
+
casecmp.zero?: 4851650.8 i/s - 1.04x (± 0.01) slower
|
382
|
+
casecmp.to_i.zero?: 4394669.1 i/s - 1.15x (± 0.02) slower
|
383
|
+
casecmp?: 3443238.5 i/s - 1.47x (± 0.02) slower
|
384
|
+
== to_s.downcase: 649351.6 i/s - 7.81x (± 0.10) slower
|
385
|
+
with 95.0% confidence
|
386
|
+
```
|
387
|
+
|
388
|
+
#### Type Case: #<StringLike:0x00007fcd21958760 @test_case="match">
|
389
|
+
|
390
|
+
```
|
391
|
+
Warming up --------------------------------------
|
392
|
+
== to_s.downcase 53.698k i/100ms
|
393
|
+
== casecmp 211.054k i/100ms
|
394
|
+
casecmp.zero? 209.614k i/100ms
|
395
|
+
casecmp.to_i.zero? 205.111k i/100ms
|
396
|
+
casecmp? 177.677k i/100ms
|
397
|
+
Calculating -------------------------------------
|
398
|
+
== to_s.downcase 642.352k (± 1.1%) i/s - 3.222M in 5.024341s
|
399
|
+
== casecmp 4.801M (± 0.9%) i/s - 24.060M in 5.023696s
|
400
|
+
casecmp.zero? 4.509M (± 0.9%) i/s - 22.638M in 5.032909s
|
401
|
+
casecmp.to_i.zero? 4.450M (± 1.2%) i/s - 22.357M in 5.044182s
|
402
|
+
casecmp? 3.332M (± 1.1%) i/s - 16.702M in 5.028767s
|
403
|
+
with 95.0% confidence
|
404
|
+
|
405
|
+
Comparison:
|
406
|
+
== casecmp: 4801157.9 i/s
|
407
|
+
casecmp.zero?: 4508944.8 i/s - 1.06x (± 0.01) slower
|
408
|
+
casecmp.to_i.zero?: 4449914.9 i/s - 1.08x (± 0.02) slower
|
409
|
+
casecmp?: 3332042.5 i/s - 1.44x (± 0.02) slower
|
410
|
+
== to_s.downcase: 642351.9 i/s - 7.47x (± 0.11) slower
|
411
|
+
with 95.0% confidence
|
412
|
+
```
|
413
|
+
|
414
|
+
#### Pre-check Case: nil
|
415
|
+
|
416
|
+
```
|
417
|
+
Warming up --------------------------------------
|
418
|
+
== casecmp(to_s) 222.939k i/100ms
|
419
|
+
casecmp?(to_s) 188.102k i/100ms
|
420
|
+
casecmp? 236.868k i/100ms
|
421
|
+
falsey casecmp.zero? 279.966k i/100ms
|
422
|
+
falsey == casecmp 282.745k i/100ms
|
423
|
+
!! casecmp.zero? 266.091k i/100ms
|
424
|
+
!! == casecmp 266.932k i/100ms
|
425
|
+
nil? casecmp.zero? 272.193k i/100ms
|
426
|
+
nil? == casecmp 273.029k i/100ms
|
427
|
+
Calculating -------------------------------------
|
428
|
+
== casecmp(to_s) 4.937M (± 1.0%) i/s - 24.746M in 5.024918s
|
429
|
+
casecmp?(to_s) 3.589M (± 1.1%) i/s - 18.058M in 5.046262s
|
430
|
+
casecmp? 6.417M (± 1.2%) i/s - 31.977M in 5.007501s
|
431
|
+
falsey casecmp.zero? 9.773M (± 1.0%) i/s - 48.714M in 5.008779s
|
432
|
+
falsey == casecmp 10.045M (± 0.9%) i/s - 50.046M in 5.001595s
|
433
|
+
!! casecmp.zero? 9.330M (± 0.9%) i/s - 46.566M in 5.009468s
|
434
|
+
!! == casecmp 8.754M (± 2.1%) i/s - 42.442M in 5.001546s
|
435
|
+
nil? casecmp.zero? 8.716M (± 1.0%) i/s - 43.551M in 5.017106s
|
436
|
+
nil? == casecmp 8.596M (± 0.8%) i/s - 42.866M in 5.000683s
|
437
|
+
with 95.0% confidence
|
438
|
+
|
439
|
+
Comparison:
|
440
|
+
falsey == casecmp: 10045375.1 i/s
|
441
|
+
falsey casecmp.zero?: 9772608.7 i/s - 1.03x (± 0.01) slower
|
442
|
+
!! casecmp.zero?: 9330161.0 i/s - 1.08x (± 0.01) slower
|
443
|
+
!! == casecmp: 8754421.4 i/s - 1.15x (± 0.03) slower
|
444
|
+
nil? casecmp.zero?: 8715727.1 i/s - 1.15x (± 0.02) slower
|
445
|
+
nil? == casecmp: 8595661.2 i/s - 1.17x (± 0.01) slower
|
446
|
+
casecmp?: 6417121.6 i/s - 1.57x (± 0.02) slower
|
447
|
+
== casecmp(to_s): 4936724.1 i/s - 2.03x (± 0.03) slower
|
448
|
+
casecmp?(to_s): 3588687.7 i/s - 2.80x (± 0.04) slower
|
449
|
+
with 95.0% confidence
|
450
|
+
```
|
451
|
+
|
452
|
+
#### Pre-check Case: "no match"
|
453
|
+
|
454
|
+
```
|
455
|
+
Warming up --------------------------------------
|
456
|
+
== casecmp(to_s) 245.036k i/100ms
|
457
|
+
casecmp?(to_s) 196.918k i/100ms
|
458
|
+
casecmp? 208.835k i/100ms
|
459
|
+
falsey casecmp.zero? 252.889k i/100ms
|
460
|
+
falsey == casecmp 253.206k i/100ms
|
461
|
+
!! casecmp.zero? 237.682k i/100ms
|
462
|
+
!! == casecmp 237.849k i/100ms
|
463
|
+
nil? casecmp.zero? 235.435k i/100ms
|
464
|
+
nil? == casecmp 242.031k i/100ms
|
465
|
+
Calculating -------------------------------------
|
466
|
+
== casecmp(to_s) 6.598M (± 1.0%) i/s - 33.080M in 5.031444s
|
467
|
+
casecmp?(to_s) 4.044M (± 1.2%) i/s - 20.283M in 5.036826s
|
468
|
+
casecmp? 4.503M (± 0.9%) i/s - 22.554M in 5.019573s
|
469
|
+
falsey casecmp.zero? 6.692M (± 0.8%) i/s - 33.634M in 5.036615s
|
470
|
+
falsey == casecmp 7.031M (± 0.9%) i/s - 35.196M in 5.018913s
|
471
|
+
!! casecmp.zero? 6.074M (± 1.1%) i/s - 30.423M in 5.029842s
|
472
|
+
!! == casecmp 6.146M (± 0.8%) i/s - 30.683M in 5.001632s
|
473
|
+
nil? casecmp.zero? 5.891M (± 0.8%) i/s - 29.429M in 5.006134s
|
474
|
+
nil? == casecmp 6.238M (± 0.8%) i/s - 31.222M in 5.015890s
|
475
|
+
with 95.0% confidence
|
476
|
+
|
477
|
+
Comparison:
|
478
|
+
falsey == casecmp: 7031044.2 i/s
|
479
|
+
falsey casecmp.zero?: 6691656.4 i/s - 1.05x (± 0.01) slower
|
480
|
+
== casecmp(to_s): 6598167.5 i/s - 1.07x (± 0.01) slower
|
481
|
+
nil? == casecmp: 6237735.7 i/s - 1.13x (± 0.01) slower
|
482
|
+
!! == casecmp: 6146232.8 i/s - 1.14x (± 0.01) slower
|
483
|
+
!! casecmp.zero?: 6073969.3 i/s - 1.16x (± 0.02) slower
|
484
|
+
nil? casecmp.zero?: 5890972.7 i/s - 1.19x (± 0.01) slower
|
485
|
+
casecmp?: 4503136.8 i/s - 1.56x (± 0.02) slower
|
486
|
+
casecmp?(to_s): 4043637.6 i/s - 1.74x (± 0.03) slower
|
487
|
+
with 95.0% confidence
|
488
|
+
```
|
@@ -5,7 +5,7 @@ require_relative 'bm_setup'
|
|
5
5
|
|
6
6
|
display_benchmark_header
|
7
7
|
|
8
|
-
INT_RANGE = (0..15)
|
8
|
+
INT_RANGE = (0..15).freeze
|
9
9
|
INT_VAR = 10
|
10
10
|
|
11
11
|
section "Integer ranges" do |bench|
|
@@ -30,7 +30,7 @@ BEGIN_OF_JULY = Time.utc(2015, 7, 1)
|
|
30
30
|
END_OF_JULY = Time.utc(2015, 7, 31)
|
31
31
|
DAY_IN_JULY = Time.utc(2015, 7, 15)
|
32
32
|
|
33
|
-
TIME_RANGE = (BEGIN_OF_JULY..END_OF_JULY)
|
33
|
+
TIME_RANGE = (BEGIN_OF_JULY..END_OF_JULY).freeze
|
34
34
|
|
35
35
|
section "Time ranges" do |bench|
|
36
36
|
bench.report('range#cover?') do
|
data/benchmarks/format_string.rb
CHANGED
@@ -15,15 +15,15 @@ MULTI_TOKEN_HASH = {
|
|
15
15
|
# rubocop:disable Style/FormatString
|
16
16
|
section "Format String" do |bench|
|
17
17
|
bench.report("String#%") do
|
18
|
-
'%10s' % 'hoge'
|
18
|
+
'%10s' % 'hoge' # rubocop:disable Style/FormatStringToken
|
19
19
|
end
|
20
20
|
|
21
21
|
bench.report("format") do
|
22
|
-
format '%10s', 'hoge'
|
22
|
+
format '%10s', 'hoge' # rubocop:disable Style/FormatStringToken
|
23
23
|
end
|
24
24
|
|
25
25
|
bench.report("sprintf") do
|
26
|
-
sprintf '%10s', 'hoge'
|
26
|
+
sprintf '%10s', 'hoge' # rubocop:disable Style/FormatStringToken
|
27
27
|
end
|
28
28
|
end
|
29
29
|
# rubocop:enable Style/FormatString
|