Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
my vs fast-deep-equal vs lodash
(version: 0)
Comparing performance of:
fast-deep-equal vs my vs lodash
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); });
lodash
data.forEach((item) => { _.isEqual(item.value1, item.value2); });
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
fast-deep-equal
my
lodash
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 data, explaining what's being tested, compared options, pros and cons of each approach, and other considerations. **Benchmark Definition** The benchmark is designed to compare three equality checking functions: 1. `my`: a custom implementation of deep equality checking (see below). 2. `fast-deep-equal`: another implementation of deep equality checking. 3. `lodash`: the Lodash library's implementation of equal function, which includes deep equality checking. **Custom Implementation (`my`)** The `my` implementation is a simple recursive function that checks for deep equality between two values: * If both values are primitive (e.g., numbers, strings), it returns true if they are equal. * If both values are objects and have the same constructor, it recursively checks their properties. * Otherwise, it returns false. The `my` implementation is a basic example of how to implement deep equality checking. However, it may not cover all edge cases, such as nested arrays or complex object structures. **Pros:** * Easy to understand and implement. * Can be optimized for performance by adding additional checks. **Cons:** * May not handle all edge cases correctly. * Not a production-ready implementation of deep equality checking. **Fast-Deep-Equal Implementation** The `fast-deep-equal` implementation is a more efficient version of the custom `my` implementation. It uses a combination of techniques, such as: * Checking for primitive values and arrays * Recursively checking object properties using a similar approach to `my` * Using a custom equality function to handle complex objects The `fast-deep-equal` implementation is likely more efficient than the custom `my` implementation due to its optimization techniques. **Pros:** * More efficient than the custom `my` implementation. * Covers more edge cases than `my`. **Cons:** * May be less intuitive for developers without experience with deep equality checking. * Still requires manual optimization and tuning for performance. **Lodash Implementation (`lodash`)** The Lodash library provides an implementation of the `equal` function, which includes deep equality checking. The `lodash` benchmark uses this implementation to compare equality between two values: 1. Check if both values are primitive or arrays 2. If objects, use a custom equality function to check properties The Lodash implementation is likely one of the most robust and widely-used implementations of deep equality checking. **Pros:** * Robust and widely-used implementation. * Handles complex edge cases correctly. **Cons:** * Requires an external library (Lodash) to be included in the benchmark. * May have a higher overhead compared to optimized implementations. In summary, the benchmark compares three implementations of deep equality checking: 1. A custom implementation (`my`) for ease of understanding and implementing. 2. An optimized implementation (`fast-deep-equal`) for efficiency. 3. The Lodash library's implementation (`lodash`) for robustness and widespread adoption. Each implementation has its pros and cons, which are discussed above.
Related benchmarks:
fast compare test w/lodash 3
lodash deepEqual vs fast-deep-equal v2
Yepo_deepEqual vs. lodash.isEqual v1.1
(JSON.stringify vs lodash vs fast-deep-equal vs fast-equals) with React and Promises
Comments
Confirm delete:
Do you really want to delete benchmark?