Skip to content

Latest commit

 

History

History
86 lines (65 loc) · 3.11 KB

File metadata and controls

86 lines (65 loc) · 3.11 KB

Deep Equality Library Benchmark Summary

Libraries Tested

  • deep-equal (v1.1.1 and v2.2.3) with strict: true
  • fast-deep-equal (v3.1.1 and v3.1.3)
  • lodash.isEqual

Key Findings

Performance Rankings

  1. fast-deep-equal - Consistently fastest across all test cases
  2. lodash.isEqual - Moderate performance, typically 20-50% of fast-deep-equal's speed
  3. deep-equal - Dramatically slower, especially v2.2.3

Performance Comparison Table

Test Case fast-deep-equal lodash.isEqual deep-equal v1.1.1 deep-equal v2.2.3
Simple objects 4.2M ops/sec 1.1M ops/sec 238K ops/sec 9K ops/sec
Nested objects 2.1M ops/sec 500K ops/sec 33K ops/sec 1.2K ops/sec
Arrays 6.2M ops/sec 2.9M ops/sec 188K ops/sec 8K ops/sec
Large objects (1000 props) 5.3K ops/sec 1.4K ops/sec 77 ops/sec 3 ops/sec
16.78MB JSON file 13ms 48ms 983ms 25,030ms

Correctness: Array vs Object Comparison

Testing [] vs {} and [1] vs {"0": 1}:

Library Result Correct?
deep-equal v1.1.1 true
deep-equal v2.2.3 false
fast-deep-equal false
lodash.isEqual false

Version Differences

deep-equal v1.1.1 vs v2.2.3

  • v1.1.1: Fast but incorrect (treats arrays and objects as equal)
  • v2.2.3: Correct but 25-1000x slower
  • The performance regression appears to be the cost of fixing correctness issues

fast-deep-equal v3.1.1 vs v3.1.3

  • No significant performance or behavioral differences
  • Both versions maintain excellent performance

Real-World Performance Impact

For a 16.78MB JSON file comparison:

  • fast-deep-equal: ~13-24ms (practical for real-time operations)
  • lodash.isEqual: ~47ms (acceptable for most use cases)
  • deep-equal v1.1.1: ~983ms (noticeable delay)
  • deep-equal v2.2.3: ~25 seconds (unusable for large data)

Recommendations

  1. Use fast-deep-equal for:

    • High-performance applications
    • Large data structures
    • Frequent equality checks
    • Real-time systems
  2. Use lodash.isEqual for:

    • Applications already using lodash
    • When moderate performance is acceptable
    • Better ecosystem integration
  3. Avoid deep-equal with strict mode for:

    • Large objects or arrays
    • Performance-critical applications
    • Any production use with v2.2.3

Technical Notes

  • All benchmarks compared two distinct objects (created via separate JSON.parse() calls)
  • The performance differences represent actual deep comparison work, not reference checks
  • fast-deep-equal has one edge case where it returns true for arrays compared to objects with Array constructor
  • All libraries correctly identify most array vs object comparisons as false

Conclusion

fast-deep-equal is the clear winner for deep equality checking in JavaScript, offering:

  • 10-1000x better performance than alternatives
  • Correct behavior in almost all cases
  • Consistent performance across versions
  • Practical performance even for very large objects