Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash vs fast-equals vs fast-deep-equal
(version: 0)
Comparing performance of:
lodash vs fast-deep-equal vs fast-equals
Created:
2 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.20/lodash.min.js"></script> <script src="https://unpkg.com/fast-equals@5.0.1/dist/min/index.js"></script>
Script Preparation code:
function equal(a, b) { if (a === b) return true; if (a && b && typeof a == 'object' && typeof b == 'object') { if (a.constructor !== b.constructor) return false; var length, i, keys; if (Array.isArray(a)) { length = a.length; if (length != b.length) return false; for (i = length; i-- !== 0;) if (!equal(a[i], b[i])) return false; return true; } if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags; if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf(); if (a.toString !== Object.prototype.toString) return a.toString() === b.toString(); keys = Object.keys(a); length = keys.length; if (length !== Object.keys(b).length) return false; for (i = length; i-- !== 0;) if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false; for (i = length; i-- !== 0;) { var key = keys[i]; if (!equal(a[key], b[key])) return false; } return true; } // true if both NaN, false otherwise return a!==a && b!==b; }; // 1 level deep var data = [ { description: 'equal numbers', value1: 1, value2: 1, equal: true, }, { description: 'not equal numbers', value1: 1, value2: 2, equal: false, }, { description: 'number and array are not equal', value1: 1, value2: [], equal: false, }, { description: '0 and null are not equal', value1: 0, value2: null, equal: false, }, { description: 'equal strings', value1: 'a', value2: 'a', equal: true, }, { description: 'big object', value1: { prop1: 'value1', prop2: 'value2', prop3: 'value3', prop4: { subProp1: 'sub value1', subProp2: { subSubProp1: 'sub sub value1', subSubProp2: [ 1, 2, { prop2: 1, prop: 2 }, 4, 5, ], }, }, prop5: 1000, prop6: new Date(2016, 2, 10), }, value2: { prop5: 1000, prop3: 'value3', prop1: 'value1', prop2: 'value2', prop6: new Date('2016/03/10'), prop4: { subProp2: { subSubProp1: 'sub sub value1', subSubProp2: [ 1, 2, { prop2: 1, prop: 2 }, 4, 5, ], }, subProp1: 'sub value1', }, }, equal: true, }, ];
Tests:
lodash
data.forEach((item) => { _.isEqual(item.value1, item.value2); });
fast-deep-equal
data.forEach((item) => { equal(item.value1, item.value2); });
fast-equals
data.forEach((item) => { window['fast-equals'].deepEqual(item.value1, item.value2); });
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
lodash
fast-deep-equal
fast-equals
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
21 hours ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36
Browser/OS:
Chrome 146 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
lodash
515552.6 Ops/sec
fast-deep-equal
2127715.0 Ops/sec
fast-equals
2432699.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll provide an in-depth explanation of the benchmark, its options, pros and cons, and other considerations. **Benchmark Overview** The benchmark is designed to compare the performance of three equality-checking libraries: Lodash's `isEqual`, Fast-Equals' `deepEqual`, and another implementation (Fast-Deep-Equal) that is not widely used. The test cases involve iterating over an array of objects with nested properties, comparing corresponding values using each library. **Library Options** 1. **Lodash (`isEqual`)**: Lodash is a popular utility library that provides a wide range of functions for various tasks, including equality checking. * Pros: + Robust feature set + Well-documented and widely adopted * Cons: + Larger bundle size compared to other libraries 2. **Fast-Equals (`deepEqual`)**: Fast-Equals is a lightweight library specifically designed for deep equality checks. * Pros: + Small bundle size (≈10KB) + Optimized for performance 3. **Fast-Deep-Equal**: This implementation is not widely used and is included in the benchmark for comparison purposes. **Pros and Cons of Each Approach** 1. **Lodash (`isEqual`)**: * Pros: Robust feature set, well-documented. * Cons: Larger bundle size, may be overkill for simple equality checks. 2. **Fast-Equals (`deepEqual`)**: * Pros: Small bundle size, optimized for performance. * Cons: Limited feature set compared to Lodash. 3. **Fast-Deep-Equal**: * Pros: None notable. * Cons: Not widely used and not well-documented. **Other Considerations** 1. **Test Cases**: The benchmark includes three test cases that cover different aspects of equality checking, including shallow and deep comparisons. 2. **Device Platforms**: The benchmark results are reported for Chrome 118 on Windows Desktop platforms. 3. **Results Interpretation**: The benchmark results indicate the number of executions per second (ExecutionsPerSecond) for each library. **Recommendations** Based on the benchmark results, Fast-Equals appears to be the fastest and most efficient option for equality checks in this scenario. However, Lodash's robust feature set and well-documented API make it a popular choice among developers. If performance is critical, using a lightweight library like Fast-Equals might be a better option.
Related benchmarks:
lodash merge vs object.assign vs spread with arrays
array object find vs _.find
Array immutable union: lodash union vs object.assign vs uniq
Array immutable union: lodash union vs object.assign vs unique
Array immutable union: lodash union vs ...new Set vs uniq
Comments
Confirm delete:
Do you really want to delete benchmark?