Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash.isEqual vs fast-deep-equal vs local
(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:
Run details:
(Test run date:
4 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:146.0) Gecko/20100101 Firefox/146.0
Browser/OS:
Firefox 146 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
lodash
387636.2 Ops/sec
fast-deep-equal
1716105.1 Ops/sec
deepEqual
653254.4 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll break down what's being tested in the provided benchmark. **Benchmark Overview** The benchmark compares three JavaScript functions for checking if two values are deeply equal: 1. `lodash.isEqual` 2. `fast-deep-equal` (custom implementation) 3. A custom `equal` function (also implemented from scratch) **What's being compared?** Each test case iterates over an array of objects (`data`) and checks if the `value1` and `value2` properties are equal using each of the three functions. **Options compared:** * Lodash's `isEqual` function * A custom implementation called `fast-deep-equal` * A custom implementation called `equal` **Key differences between options:** 1. **Lodash's `isEqual`**: A widely used and well-maintained library function that checks for deep equality. It handles complex data structures like arrays, objects, and nested objects. 2. **Fast-Deep-Equal**: A custom implementation that uses a similar approach to Lodash's `isEqual`. However, the implementation is not as thoroughly tested or maintained. 3. **Custom `equal` function**: Another custom implementation that checks for deep equality. This function may have its own optimization techniques or edge cases. **What does the benchmark result tell us?** The benchmark results show the execution speed of each function on a specific browser and device configuration (Chrome 129 on Mac OS X 10.15.7). The results indicate that: * Lodash's `isEqual` is the fastest among the three options. * The custom `fast-deep-equal` implementation is slower than Lodash's `isEqual`, but faster than the custom `equal` function. * The custom `equal` function is the slowest among the three options. **Takeaways** The benchmark suggests that: 1. Lodash's `isEqual` is a reliable and efficient choice for deep equality checks, especially for complex data structures. 2. Custom implementations like `fast-deep-equal` can be optimized for performance but may not match the quality and reliability of well-maintained libraries like Lodash. 3. Writing custom functions from scratch can lead to suboptimal performance compared to using established libraries or frameworks. Keep in mind that benchmark results are specific to this particular browser and device configuration, so it's essential to consider other factors, such as code readability, maintainability, and scalability, when choosing a function for deep equality checks.
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?