Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
arty lodash.isEqual vs fast-deep-equal
(version: 0)
Comparing performance of:
lodash vs fast-deep-equal
Created:
2 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 excludedProps = [ 'prop4', 'prop6', ]; 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( _.omit(item.value1,excludedProps), _.omit(item.value2,excludedProps)); });
fast-deep-equal
data.forEach((item) => { equal(item.value1, item.value2, excludedProps); });
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
lodash
fast-deep-equal
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 benchmark definition and explain what's being tested, compared, and their pros/cons. **Benchmark Definition** The benchmark is testing two functions: `_.isEqual` from the Lodash library and `fast-deep-equal`. Both functions are used to compare two objects for equality. **What is tested?** * The test case consists of 7 individual test cases (`data.forEach`) that iterate over an array of objects. * Each object has two properties (`value1` and `value2`) with different values, including numbers, arrays, null, and dates. * The benchmark tests the performance of both `_.isEqual` and `fast-deep-equal` functions to compare these two objects. **Options compared** The benchmark compares two options: 1. **Lodash's _.isEqual**: A widely-used library function that recursively checks for deep equality between objects. 2. **fast-deep-equal**: A custom implementation of deep equality checking, likely optimized for performance. **Pros and Cons of each approach** **_.isEqual (Lodash)** Pros: * Wide adoption and familiarity in the developer community * Handles various edge cases, such as NaNs, dates, and null/undefined values * Well-tested and stable Cons: * May be slower than custom implementations due to overhead of library functions * Additional dependency on Lodash library **fast-deep-equal** Pros: * Optimized for performance, potentially faster execution * No additional dependencies or library overhead Cons: * May not handle all edge cases as thoroughly as _.isEqual * Requires manual implementation and testing to ensure correctness **Other considerations** * The benchmark uses a custom `equal` function that simply checks for reference equality (`a === b`). This is likely done to isolate the performance difference between `_._isEqual` and `fast-deep-equal`. * The `excludedProps` array defines which properties are ignored during comparison. Both functions use this array, but `_.isEqual` also uses a more comprehensive approach to ignore properties. **Alternatives** Other alternatives for deep equality checking include: * JSON.stringify() + === (a simple, but not optimized, approach) * deep-equal-js (another lightweight implementation) * Recurse.js (a recursive function for checking equality) Note that these alternatives might have different performance characteristics and may require additional considerations. The benchmark result shows the performance difference between `fast-deep-equal` and `_._isEqual`, with `fast-deep-equal` outperforming Lodash's implementation.
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
arty 2 lodash.isEqual vs fast-deep-equal
lodash vs fast-equals vs fast-deep-equal
Comments
Confirm delete:
Do you really want to delete benchmark?