liufengyun / hashdiff

Hashdiff is a ruby library to to compute the smallest difference between two hashes
MIT License
560 stars 63 forks source link

Optimize nils #55

Closed krzysiek1507 closed 5 years ago

krzysiek1507 commented 5 years ago
Before:

obj1 = obj2 = nil

Warming up --------------------------------------
                diff    44.874k i/100ms
Calculating -------------------------------------
                diff    580.061k (± 4.9%) i/s -      2.917M in   5.041213s
Calculating -------------------------------------
                diff   968.000  memsize (     0.000  retained)
                         2.000  objects (     0.000  retained)
                         0.000  strings (     0.000  retained)

obj1 = obj2 = {:a=>nil, :b=>nil, :c=>nil, :d=>nil, :e=>nil, :f=>nil, :g=>nil}

Warming up --------------------------------------
                diff     2.990k i/100ms
Calculating -------------------------------------
                diff     30.987k (± 2.1%) i/s -    155.480k in   5.019802s
Calculating -------------------------------------
                diff    17.128k memsize (     0.000  retained)
                        52.000  objects (     0.000  retained)
                         7.000  strings (     0.000  retained)

After:

obj1 = obj2 = nil

Warming up --------------------------------------
                diff   173.449k i/100ms
Calculating -------------------------------------
                diff      3.836M (± 1.4%) i/s -     19.253M in   5.019826s
Calculating -------------------------------------
                diff    40.000  memsize (     0.000  retained)
                         1.000  objects (     0.000  retained)
                         0.000  strings (     0.000  retained)

obj1 = obj2 = {:a=>nil, :b=>nil, :c=>nil, :d=>nil, :e=>nil, :f=>nil, :g=>nil}

Warming up --------------------------------------
                diff     4.551k i/100ms
Calculating -------------------------------------
                diff     46.585k (± 3.3%) i/s -    236.652k in   5.085934s
Calculating -------------------------------------
                diff    10.632k memsize (     0.000  retained)
                        45.000  objects (     0.000  retained)
                         7.000  strings (     0.000  retained)