Skip to content

Commit

Permalink
Check objects individually
Browse files Browse the repository at this point in the history
obj1 = 1, obj2 = 1.1, numeric_tolerance = 0.1

Warming up --------------------------------------
            original   106.128k i/100ms
           optimized   161.873k i/100ms
Calculating -------------------------------------
            original      1.682M (± 5.8%) i/s -      8.384M in   5.005149s
           optimized      3.560M (± 2.4%) i/s -     17.806M in   5.005019s

Comparison:
           optimized:  3559889.7 i/s
            original:  1682449.9 i/s - 2.12x  slower

Calculating -------------------------------------
            original    40.000  memsize (     0.000  retained)
                         1.000  objects (     0.000  retained)
                         0.000  strings (     0.000  retained)
           optimized     0.000  memsize (     0.000  retained)
                         0.000  objects (     0.000  retained)
                         0.000  strings (     0.000  retained)

Comparison:
           optimized:          0 allocated
            original:         40 allocated - Infx more
  • Loading branch information
krzysiek1507 committed Apr 18, 2019
1 parent c55d171 commit 25e61ad
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions lib/hashdiff/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ def self.node(hash, parts)
#
# check for equality or "closeness" within given tolerance
def self.compare_values(obj1, obj2, options = {})
if (options[:numeric_tolerance].is_a? Numeric) &&
[obj1, obj2].all? { |v| v.is_a? Numeric }
if options[:numeric_tolerance].is_a?(Numeric) && obj1.is_a?(Numeric) && obj2.is_a?(Numeric)
return (obj1 - obj2).abs <= options[:numeric_tolerance]
end

Expand Down

0 comments on commit 25e61ad

Please sign in to comment.