File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -719,6 +719,23 @@ Comparison:
719719 Hash#merge!: 10653.3 i/s - 2.66x slower
720720```
721721
722+ ##### ` Hash#merge ` vs ` Hash#**other ` [ code] ( code/hash/merge-vs-double-splat-operator.rb )
723+
724+ ```
725+ $ ruby -v merge-vs-double-splat-operator.rb
726+ ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-darwin15]
727+ Warming up --------------------------------------
728+ Hash#**other 64.624k i/100ms
729+ Hash#merge 38.827k i/100ms
730+ Calculating -------------------------------------
731+ Hash#**other 798.397k (± 6.9%) i/s - 4.007M in 5.053516s
732+ Hash#merge 434.171k (± 4.5%) i/s - 2.174M in 5.018927s
733+
734+ Comparison:
735+ Hash#**other: 798396.6 i/s
736+ Hash#merge: 434170.8 i/s - 1.84x slower
737+ ```
738+
722739##### ` Hash#merge ` vs ` Hash#merge! ` [ code] ( code/hash/merge-vs-merge-bang.rb )
723740
724741```
Original file line number Diff line number Diff line change 1+ require 'benchmark/ips'
2+
3+ def fast
4+ h2 = { a : 'a' }
5+ { one : 1 , **h2 }
6+ end
7+
8+ def slow
9+ h2 = { a : 'a' }
10+ { one : 1 } . merge ( h2 )
11+ end
12+
13+ Benchmark . ips do |x |
14+ x . report ( 'Hash#**other' ) { fast }
15+ x . report ( 'Hash#merge' ) { slow }
16+ x . compare!
17+ end
You can’t perform that action at this time.
0 commit comments