@@ -207,7 +207,7 @@ Comparison:
207
207
ancestors.include?: 192602.9 i/s - 6.49x slower
208
208
```
209
209
210
- #### Method Invocation
210
+ ### Method Invocation
211
211
212
212
##### ` call ` vs ` send ` vs ` method_missing ` [ code] ( code/method/call-vs-send-vs-method_missing.rb )
213
213
@@ -309,8 +309,7 @@ Comparison:
309
309
##### Kernel#format vs Float#round().to_s [ code] ( code/general/format-vs-round-and-to-s.rb )
310
310
311
311
```
312
- $ ruby -v code/general/format-vs-round-and-t
313
- o-s.rb
312
+ $ ruby -v code/general/format-vs-round-and-to-s.rb
314
313
ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-darwin15]
315
314
Warming up --------------------------------------
316
315
Float#round 106.645k i/100ms
@@ -561,6 +560,7 @@ Similar comparisons hold for `Enumerable#sort_by.last` vs
561
560
` Enumerable#sort.last ` vs ` Enumerable#max ` .
562
561
563
562
```
563
+ $ ruby -v code/enumerable/sort_by-first-vs-min_by.rb
564
564
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin17]
565
565
Warming up --------------------------------------
566
566
Enumerable#min_by 15.170k i/100ms
@@ -638,7 +638,7 @@ Enumerable#sort_by (Symbol#to_proc): 25916.1 i/s
638
638
Of note, ` to_proc ` for 1.8.7 is considerable slower than the block format
639
639
640
640
```
641
- $ ruby -v code/enumerable/inject-sum -vs-block.rb
641
+ $ ruby -v code/enumerable/inject-symbol -vs-block.rb
642
642
ruby 2.2.4p230 (2015-12-16 revision 53155) [x86_64-darwin14]
643
643
Warming up --------------------------------------
644
644
inject symbol 1.893k i/100ms
@@ -805,13 +805,14 @@ Comparison:
805
805
Hash#keys.each: 869262.3 i/s - 1.21x slower
806
806
```
807
807
808
- #### ` Hash#key? ` instead of ` Hash#keys.include? ` [ code] ( code/hash/keys-include-vs-\[\] -vs- key.rb )
808
+ #### ` Hash#key? ` instead of ` Hash#keys.include? ` [ code] ( code/hash/keys-include-vs-key.rb )
809
809
810
810
> ` Hash#keys.include? ` allocates an array of keys and performs an O(n) search; <br >
811
811
> ` Hash#key? ` performs an O(1) hash lookup without allocating a new array.
812
812
813
813
```
814
- $ ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin17]
814
+ $ ruby -v code/hash/keys-include-vs-key.rb
815
+ ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin17]
815
816
816
817
Calculating -------------------------------------
817
818
Hash#keys.include? 8.612k (± 2.5%) i/s - 43.248k in 5.024749s
@@ -861,7 +862,7 @@ Comparison:
861
862
##### ` Hash#merge ` vs ` Hash#**other ` [ code] ( code/hash/merge-vs-double-splat-operator.rb )
862
863
863
864
```
864
- $ ruby -v merge-vs-double-splat-operator.rb
865
+ $ ruby -v code/hash/ merge-vs-double-splat-operator.rb
865
866
ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-darwin15]
866
867
Warming up --------------------------------------
867
868
Hash#**other 64.624k i/100ms
@@ -937,8 +938,7 @@ Comparison:
937
938
sort + to_h: 81972.8 i/s - 1.49x slower
938
939
```
939
940
940
- ##### Native ` Hash#slice ` vs other slice implementations before native
941
- [ code] ( code/hash/slice-native-vs-before-native.rb )
941
+ ##### Native ` Hash#slice ` vs other slice implementations before native [ code] ( code/hash/slice-native-vs-before-native.rb )
942
942
943
943
Since ruby 2.5, Hash comes with a ` slice ` method to select hash members by keys.
944
944
@@ -1053,15 +1053,15 @@ always `ASCII-8BIT` encoded instead of the script encoding (usually `UTF-8`).
1053
1053
1054
1054
```
1055
1055
$ ruby -v code/string/dup-vs-unary-plus.rb
1056
- ruby 2.4.3p205 (2017-12-14 revision 61247) [x86_64-darwin17]
1056
+ ruby 2.4.3p205 (2017-12-14 revision 61247) [x86_64-darwin17]
1057
1057
1058
- Calculating -------------------------------------
1059
- String#+@ 7.697M (± 1.4%) i/s - 38.634M in 5.020313s
1060
- String#dup 3.566M (± 1.0%) i/s - 17.860M in 5.008377s
1058
+ Calculating -------------------------------------
1059
+ String#+@ 7.697M (± 1.4%) i/s - 38.634M in 5.020313s
1060
+ String#dup 3.566M (± 1.0%) i/s - 17.860M in 5.008377s
1061
1061
1062
- Comparison:
1063
- String#+@: 7697108.3 i/s
1064
- String#dup: 3566485.7 i/s - 2.16x slower
1062
+ Comparison:
1063
+ String#+@: 7697108.3 i/s
1064
+ String#dup: 3566485.7 i/s - 2.16x slower
1065
1065
```
1066
1066
1067
1067
##### ` String#casecmp ` vs ` String#downcase + == ` [ code] ( code/string/casecmp-vs-downcase-==.rb )
@@ -1126,17 +1126,17 @@ longer. For short strings, `String#match?` performs similarly to
1126
1126
1127
1127
```
1128
1128
$ ruby -v code/string/start-string-checking-match-vs-start_with.rb
1129
- ruby 2.4.3p205 (2017-12-14 revision 61247) [x86_64-darwin17]
1129
+ ruby 2.4.3p205 (2017-12-14 revision 61247) [x86_64-darwin17]
1130
1130
1131
- Calculating -------------------------------------
1132
- String#=~ 1.088M (± 4.0%) i/s - 5.471M in 5.034404s
1133
- String#match? 5.138M (± 5.0%) i/s - 25.669M in 5.008810s
1134
- String#start_with? 6.314M (± 4.3%) i/s - 31.554M in 5.007207s
1131
+ Calculating -------------------------------------
1132
+ String#=~ 1.088M (± 4.0%) i/s - 5.471M in 5.034404s
1133
+ String#match? 5.138M (± 5.0%) i/s - 25.669M in 5.008810s
1134
+ String#start_with? 6.314M (± 4.3%) i/s - 31.554M in 5.007207s
1135
1135
1136
- Comparison:
1137
- String#start_with?: 6314182.0 i/s
1138
- String#match?: 5138115.1 i/s - 1.23x slower
1139
- String#=~: 1088461.5 i/s - 5.80x slower
1136
+ Comparison:
1137
+ String#start_with?: 6314182.0 i/s
1138
+ String#match?: 5138115.1 i/s - 1.23x slower
1139
+ String#=~: 1088461.5 i/s - 5.80x slower
1140
1140
```
1141
1141
1142
1142
```
@@ -1397,7 +1397,7 @@ Comparison:
1397
1397
1398
1398
### Range
1399
1399
1400
- #### ` cover? ` vs ` include? ` [ code] ( code/range/cover-vs-include.rb )
1400
+ ##### ` cover? ` vs ` include? ` [ code] ( code/range/cover-vs-include.rb )
1401
1401
1402
1402
` cover? ` only check if it is within the start and end, ` include? ` needs to traverse the whole range.
1403
1403
0 commit comments