Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash.isEqual vs fast-deep-equal vs local 22221
(version: 0)
Comparing performance of:
lodash vs fast-deep-equal vs deepEqual
Created:
3 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.20/lodash.min.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 object are not equal', value1: 0, value2: {}, 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); });
deepEqual
function deepEqual(object1, object2) { const keys1 = Object.keys(object1); const keys2 = Object.keys(object2); if (keys1.length !== keys2.length) { return false; } for (const key of keys1) { const val1 = object1[key]; const val2 = object2[key]; const areObjects = isObject(val1) && isObject(val2); if ( areObjects && !deepEqual(val1, val2) || !areObjects && val1 !== val2 ) { return false; } } return true; } function isObject(object) { return object != null && typeof object === 'object'; } data.forEach((item) => { 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
deepEqual
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll break down the provided JSON and explain what's being tested, compared, and analyzed. **Benchmark Overview** The benchmark compares the performance of three different equality checks: `lodash.isEqual`, `fast-deep-equal`, and a custom implementation (also called "equal" in the code). The test data consists of an array of objects with various properties, including numbers, arrays, and objects. **Tested Approaches** 1. **Lodash's isEqual**: This is a popular JavaScript library function that checks for deep equality between two values. 2. **fast-deep-equal**: This is a custom implementation that performs a deep comparison of two values. It's likely inspired by the `lodash` implementation but optimized for performance. 3. **Custom Equal Function (equal)**: This is the custom implementation provided in the benchmark code. It's designed to be fast and efficient, but its performance might not match the optimized `fast-deep-equal`. **Comparison** The benchmark runs each of these three functions on the test data and measures their performance in terms of executions per second. The browser, device platform, operating system, and raw UA string are also recorded for each execution. **Analysis** By comparing the performance of these three approaches, the benchmark provides insights into: * **Lodash's isEqual**: Its performance might be slower than expected due to its widespread use and potential overhead. * **fast-deep-equal**: This implementation appears to be optimized for performance, but its exact performance might depend on the specific use case and data. * **Custom Equal Function (equal)**: The benchmark shows that this custom implementation is not as fast as `fast-deep-equal`, suggesting that it may require additional optimizations or tweaks. **Takeaways** Based on the benchmark results, if you need to perform deep equality checks in your application: * Consider using a well-maintained and optimized library like Lodash's `isEqual`. * If performance is critical, look into `fast-deep-equal` or similar implementations. * Avoid rolling your own custom equality check unless you have specific requirements that necessitate a bespoke solution. Keep in mind that this benchmark might not be representative of all scenarios, and other factors like data size and complexity could impact the results.
Related benchmarks:
fast compare test w/lodash 3
lodash deepEqual vs fast-deep-equal v2
lodash.isEqual vs fast-deep-equal vs stable-hash-compare
lodash vs fast-equals vs fast-deep-equal
lodash.isEqual vs fast-deep-equal vs local 2
Comments
Confirm delete:
Do you really want to delete benchmark?