Skip to content

Commit

Permalink
Merge pull request #106 from lvl0nax/fix_for_hash_merges
Browse files Browse the repository at this point in the history
little fix for the hash merge comparison
  • Loading branch information
Arcovion committed Apr 27, 2016
2 parents b7a8b74 + 864ed54 commit f63cf7c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
20 changes: 10 additions & 10 deletions README.md
Expand Up @@ -707,21 +707,21 @@ Comparison:
```
$ ruby -v code/hash/merge-bang-vs-merge-vs-dup-merge-bang.rb
ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin14]
ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-linux]
Calculating -------------------------------------
{}#merge!(Hash) 1.082k i/100ms
Hash#merge({}) 422.000 i/100ms
Hash#dup#merge!({}) 419.000 i/100ms
{}#merge!(Hash) do end 2.006k i/100ms
Hash#merge({}) 762.000 i/100ms
Hash#dup#merge!({}) 736.000 i/100ms
-------------------------------------------------
{}#merge!(Hash) 11.161k5.1%) i/s - 56.264k
Hash#merge({}) 4.449k3.8%) i/s - 22.366k
Hash#dup#merge!({}) 4.340k6.2%) i/s - 21.788k
{}#merge!(Hash) do end 20.055k2.0%) i/s - 100.300k in 5.003322s
Hash#merge({}) 7.676k1.2%) i/s - 38.862k in 5.063382s
Hash#dup#merge!({}) 7.440k1.1%) i/s - 37.536k in 5.045851s
Comparison:
{}#merge!(Hash): 11161.3 i/s
Hash#merge({}): 4449.4 i/s - 2.51x slower
Hash#dup#merge!({}): 4340.3 i/s - 2.57x slower
{}#merge!(Hash) do end: 20054.8 i/s
Hash#merge({}): 7676.3 i/s - 2.61x slower
Hash#dup#merge!({}): 7439.9 i/s - 2.70x slower
```

##### `Hash#sort_by` vs `Hash#sort` [code](code/hash/hash-key-sort_by-vs-sort.rb)
Expand Down
4 changes: 2 additions & 2 deletions code/hash/merge-bang-vs-merge-vs-dup-merge-bang.rb
Expand Up @@ -5,7 +5,7 @@

def fast
ENUM.inject([]) do |accumulator, element|
accumulator << { bar: element }.merge!(ORIGINAL_HASH)
accumulator << ({ bar: element }.merge!(ORIGINAL_HASH){ |_key, left, _right| left })
end
end

Expand All @@ -22,7 +22,7 @@ def slow_dup
end

Benchmark.ips do |x|
x.report("{}#merge!(Hash)") { fast }
x.report("{}#merge!(Hash) do end") { fast }
x.report("Hash#merge({})") { slow }
x.report("Hash#dup#merge!({})") { slow_dup }
x.compare!
Expand Down

0 comments on commit f63cf7c

Please sign in to comment.