Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
my vs fast-deep-equal
(version: 0)
Comparing performance of:
fast-deep-equal vs my
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 deepEqual(x, y) { if (x === y) return true; else if ((typeof x == "object" && x != null) && (typeof y == "object" && y != null)) { if (Object.keys(x).length !== Object.keys(y).length) return false; for (var prop in x) { if (y.hasOwnProperty(prop)) { if (! deepEqual(x[prop], y[prop])) return false; }else return false; } return true; } else return false; } 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:
fast-deep-equal
data.forEach((item) => { equal(item.value1, item.value2); });
my
data.forEach((item) => { deepEqual(item.value1, item.value2); });
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
fast-deep-equal
my
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 Definition** The benchmark is comparing two custom equality functions: 1. `deepEqual(x, y)`: This function checks if two values are deeply equal, meaning it recursively checks all nested properties of objects. 2. `equal(a, b)`: This function checks if two values are shallowly equal, meaning it only compares the top-level properties of objects. **Comparison** The benchmark is comparing these two functions on a dataset of 5 test cases: 1. Equal numbers 2. Not equal numbers 3. Number and array are not equal 4. 0 and null are not equal 5. Equal strings Each test case has an "equal" property indicating whether the expected result should be `true` or `false`. **Options** There are two options being compared: 1. **deepEqual(x, y)**: This function uses a recursive approach to check for deep equality. 2. **equal(a, b)**: This function uses a shallow approach to check for equality. **Pros and Cons** * **deepEqual(x, y)**: + Pros: - More accurate results when dealing with complex nested objects. + Cons: - Can be slower due to the recursive nature of the comparison. * **equal(a, b)**: + Pros: - Faster execution times compared to `deepEqual`. + Cons: - May produce incorrect results for deeply nested objects. **Library** The benchmark uses a third-party library called Lodash (version 4.17.20) for its `lodash.min.js` file, which is included in the HTML Preparation Code section of the benchmark definition. Lodash provides various utility functions, including `isEqual`, which can be used to implement the equality comparison logic. **Device and Browser Information** The latest benchmark results include information about the device (Desktop, Linux) and browser (Chrome 97) being used for the tests. This information is likely used to analyze performance differences between devices and browsers. By comparing these two custom equality functions, the benchmark aims to evaluate their performance and accuracy in different scenarios, ultimately helping developers choose the most suitable function for their specific use cases.
Related benchmarks:
fast compare test w/lodash 3
lodash deepEqual vs fast-deep-equal v2
my vs fast-deep-equal vs lodash
fast Deep Equal vs JSON.stringify Equality Comparison for very large arrays of nested numbers
Comments
Confirm delete:
Do you really want to delete benchmark?