Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Test fast deep equal
(version: 0)
Comparing performance of:
lodash vs fast-deep-equal
Created:
4 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 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); });
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 provided benchmark and explain what's being tested, compared, and their pros and cons. **Benchmark Overview** The benchmark is designed to measure the performance of two JavaScript functions: `_.isEqual` from the Lodash library and a custom function named `equal`. Both functions are used to compare the equality of two values in an array. **Custom Function (Fast-Deep-Equal)** The custom function `equal` is responsible for checking if two values are equal. It's designed to handle nested objects, arrays, and primitive types. Here's a high-level overview of its logic: 1. Checks if both values are equal using the `===` operator. 2. If one value is an object and the other is not, it returns false. 3. If both values are objects, it checks their constructors, lengths, and keys to ensure they're equal. **Lodash Function (_.isEqual)** The Lodash function `_.`(isEqual) is designed to check if two values are equal. It's a more comprehensive implementation than the custom `equal` function. 1. Handles nested objects, arrays, and primitive types. 2. Uses a recursive approach to compare the equality of complex data structures. **Comparison** Both functions aim to achieve the same goal: checking if two values are equal. However, they differ in their approach: * The `equal` function uses a more straightforward, iterative approach, which might be faster for small arrays but could become slower for larger datasets. * The Lodash `_.`(isEqual) function is more comprehensive and optimized for performance, making it suitable for handling large datasets. **Pros and Cons** **Custom Function (Fast-Deep-Equal)** Pros: * Simpler implementation * Might be faster for small arrays Cons: * Less comprehensive than the Lodash implementation * May not handle complex data structures as well **Lodash Function (_.isEqual)** Pros: * Comprehensive implementation that handles most cases * Optimized for performance Cons: * More complex implementation * Might have a slight overhead due to its recursive nature **Other Considerations** * The benchmark uses the `forEach` method, which might not be the best approach for measuring performance. Other methods like `for` loops or `map` functions could provide more accurate results. * The Lodash library is included via a CDN, which might introduce additional overhead. Overall, both implementations have their strengths and weaknesses. While the custom `equal` function is simple and lightweight, it's less comprehensive than the Lodash implementation. In contrast, the Lodash `_.`(isEqual) function offers better performance and handling of complex data structures, making it a more suitable choice for large-scale applications.
Related benchmarks:
fast compare test
fast compare test w/lodash 3
Underscore isEqual, fast-deep-equal test
lodash.isEqual vs fast-deep-equal vs stable-hash-compare
Comments
Confirm delete:
Do you really want to delete benchmark?