Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
fast_deep_equal - lodash.isEqual
(version: 0)
Comparing performance of:
lodash vs fast-deep-equal vs JSON
Created:
7 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.4/lodash.min.js"></script>
Script Preparation code:
var isArray = Array.isArray; var keyList = Object.keys; var hasProp = Object.prototype.hasOwnProperty; function equal(a, b) { if (a === b) return true; if (a && b && typeof a == 'object' && typeof b == 'object') { var arrA = isArray(a) , arrB = isArray(b) , i , length , key; if (arrA && arrB) { 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 (arrA != arrB) return false; var dateA = a instanceof Date , dateB = b instanceof Date; if (dateA != dateB) return false; if (dateA && dateB) return a.getTime() == b.getTime(); var regexpA = a instanceof RegExp , regexpB = b instanceof RegExp; if (regexpA != regexpB) return false; if (regexpA && regexpB) return a.toString() == b.toString(); var keys = keyList(a); length = keys.length; if (length !== keyList(b).length) return false; for (i = length; i-- !== 0;) if (!hasProp.call(b, keys[i])) return false; for (i = length; i-- !== 0;) { key = keys[i]; if (!equal(a[key], b[key])) return false; } return true; } return a!==a && b!==b; }; // 1 level deep window.foo1 = { a: 1, b: 2, c: { a: 1, b: 2, c: { a: 1, b: 2 } } }; window.bar1 = { a: 1, b: 3, c: { a: 1, b: 2, c: { a: 1, b: 2 } } }; // 2 levels deep window.foo2 = { a: 1, b: 2, c: { a: 1, b: 2, c: { a: 1, b: 2 } } }; window.bar2 = { a: 1, b: 2, c: { a: 1, b: 3, c: { a: 1, b: 2 } } }; // 3 levels deep window.foo3 = { a: 1, b: 2, c: { a: 1, b: 2, c: { a: 1, b: 2 } } }; window.bar3 = { a: 1, b: 2, c: { a: 1, b: 2, c: { a: 1, b: 4 } } };
Tests:
lodash
_.isEqual(window.foo1, window.bar1)
fast-deep-equal
equal(window.foo1, window.bar1);
JSON
JSON.stringify(window.foo1) === JSON.stringify(window.bar1);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
lodash
fast-deep-equal
JSON
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 definition and explain what's being tested, compared, and their pros and cons. **Benchmark Definition** The benchmark is defined as a JSON object that contains three test cases: 1. `_.isEqual(window.foo1, window.bar1)`: Tests the implementation of the `isEqual` function from the Lodash library. 2. `equal(window.foo1, window.bar1);`: Tests the custom implementation of the `fast-deep-equal` function. 3. `JSON.stringify(window.foo1) === JSON.stringify(window.bar1);`: Tests the equality of two JSON strings. **Options Compared** The three test cases compare different approaches to deep equality checking: * **Lodash's `isEqual` function**: A widely used and well-tested library function for deep equality checks. * **Custom implementation of `fast-deep-equal`**: A custom function that attempts to outperform Lodash's `isEqual` function. However, this implementation has a higher chance of introducing bugs or performance issues. **Pros and Cons** Here are some pros and cons associated with each approach: * **Lodash's `isEqual` function**: + Pros: Well-tested, widely adopted, and maintains consistency across different browsers. + Cons: May not be the fastest option due to its complexity and dependency on other Lodash functions. * **Custom implementation of `fast-deep-equal`**: + Pros: Can potentially outperform Lodash's `isEqual` function in terms of performance. + Cons: Higher risk of introducing bugs or performance issues, as it's a custom implementation with less testing and validation. **Library and Its Purpose** The Lodash library is a popular JavaScript utility library that provides a set of functions for various tasks, including deep equality checks. In this benchmark, the `isEqual` function from Lodash is used to test its implementation. **Special JS Features or Syntax** There are no special JS features or syntax used in these benchmarks. The focus is on testing the performance and correctness of different approaches to deep equality checks. **Other Alternatives** If you're interested in exploring alternative libraries or implementations for deep equality checks, here are a few options: * **Underscore.js**: Another popular JavaScript utility library that provides a `deepEqual` function similar to Lodash's `isEqual`. * **fast-deep-equal**: A lightweight implementation of the fast-deep-equal algorithm, which is also used in this benchmark. * ** JSON-based equality checks**: Some libraries or implementations use JSON-based approaches for deep equality checks, such as comparing JSON strings. Keep in mind that these alternatives may have different strengths and weaknesses compared to Lodash's `isEqual` function.
Related benchmarks:
comparing while vs for loop (v10)
fast compare test
fast compare test w/lodash 3
lodash vs fast-deep-equal using fast-deep-equal's tests
Comments
Confirm delete:
Do you really want to delete benchmark?