@@ -937,24 +937,33 @@ Comparison:
937
937
sort + to_h: 81972.8 i/s - 1.49x slower
938
938
```
939
939
940
- ##### ` Hash#slice ` vs ` Hash#select{ includes? } ` [ code] ( code/hash/slice-vs-select-include.rb )
940
+ ##### Native ` Hash#slice ` vs other slice implementations before native
941
+ [ code] ( code/hash/slice-native-vs-before-native.rb )
941
942
942
943
Since ruby 2.5, Hash comes with a ` slice ` method to select hash members by keys.
943
944
944
945
```
945
- $ ruby code/hash/slice-vs-select-include .rb
946
+ $ ruby -v code/hash/slice-native- vs-before-native .rb
946
947
ruby 2.5.3p105 (2018-10-18 revision 65156) [x86_64-linux]
947
-
948
+ Warming up --------------------------------------
949
+ Hash#native-slice 178.077k i/100ms
950
+ Array#each 124.311k i/100ms
951
+ Array#each_w/_object 110.818k i/100ms
952
+ Hash#select-include 66.972k i/100ms
948
953
Calculating -------------------------------------
949
- Hash#slice 3.124M (± 0.6%) i/s - 15.675M in 5.017984s
950
- Hash#select_if_includes
951
- 1.342M (± 1.1%) i/s - 6.716M in 5.003901s
954
+ Hash#native-slice 2.540M (± 1.5%) i/s - 12.822M in 5.049955s
955
+ Array#each 1.614M (± 1.0%) i/s - 8.080M in 5.007925s
956
+ Array#each_w/_object 1.353M (± 2.6%) i/s - 6.760M in 5.000441s
957
+ Hash#select-include 760.944k (± 0.9%) i/s - 3.817M in 5.017123s
952
958
953
959
Comparison:
954
- Hash#slice: 3123803.2 i/s
955
- Hash#select_if_includes: 1342270.6 i/s - 2.33x slower
960
+ Hash#native-slice : 2539515.5 i/s
961
+ Array#each : 1613665.5 i/s - 1.57x slower
962
+ Array#each_w/_object: 1352851.8 i/s - 1.88x slower
963
+ Hash#select-include : 760944.2 i/s - 3.34x slower
956
964
```
957
965
966
+
958
967
### Proc & Block
959
968
960
969
##### Block vs ` Symbol#to_proc ` [ code] ( code/proc-and-block/block-vs-to_proc.rb )
0 commit comments