Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash isEqual test 4.17.15
(version: 0)
Test on isEqual performance
Comparing performance of:
_.isEqual Level 1 vs JSON.stringify Level 1 vs _.isEqual Level 2 vs JSON.stringify Level 2 vs _.isEqual Level 3 vs JSON.stringify Level 3
Created:
6 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.15/lodash.min.js"></script>
Script Preparation code:
// 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:
_.isEqual Level 1
_.isEqual(window.foo1, window.bar1)
JSON.stringify Level 1
JSON.stringify(window.foo1) === JSON.stringify(window.bar1);
_.isEqual Level 2
_.isEqual(window.foo2, window.bar2)
JSON.stringify Level 2
JSON.stringify(window.foo2) === JSON.stringify(window.bar2);
_.isEqual Level 3
_.isEqual(window.foo3, window.bar3)
JSON.stringify Level 3
JSON.stringify(window.foo3) === JSON.stringify(window.bar3);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (6)
Previous results
Fork
Test case name
Result
_.isEqual Level 1
JSON.stringify Level 1
_.isEqual Level 2
JSON.stringify Level 2
_.isEqual Level 3
JSON.stringify Level 3
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):
Let's dive into the explanation of what's being tested in this benchmark. **Overview** The benchmark tests the performance of Lodash's `isEqual` function, which is used to compare two objects for equality. The test cases use different approaches to compare the objects, including direct comparison using `_.isEqual`, string comparison using `JSON.stringify`. **Options compared** The following options are being compared: 1. **Direct comparison**: `_._isEqual(window.foo1, window.bar1)` 2. **String comparison**: `JSON.stringify(window.foo1) === JSON.stringify(window.bar1)` **Pros and Cons of each approach:** * **Direct comparison**: This is the most straightforward way to compare two objects. It's fast because it doesn't require any additional processing. + Pros: Fast, easy to implement + Cons: May not work correctly for complex object structures (e.g., nested arrays or objects) * **String comparison**: + Uses `JSON.stringify` to convert the objects to strings + Can be slower than direct comparison because of the additional processing required + Pros: Works correctly for all object structures, including nested arrays and objects + Cons: Slower than direct comparison **Other considerations** * **Memoization**: Lodash's `isEqual` function is memoized, which means that it caches the results of previous comparisons to avoid repeated calculations. This can improve performance if the same comparison is performed multiple times. * **Browser-specific behavior**: The benchmark is run on a Chrome browser, which may exhibit different behavior than other browsers. **Lodash library** The `lodash` library provides a collection of reusable functions for common programming tasks. In this case, it's used to implement the `isEqual` function, which compares two objects for equality. **Special JS feature or syntax: None** There are no special JavaScript features or syntax being tested in this benchmark. **Alternative approaches** If you wanted to write your own custom comparison function instead of using Lodash's `isEqual`, you could consider using a recursive approach to compare the properties of two objects. Here's an example: ```javascript function customIsEqual(obj1, obj2) { if (typeof obj1 !== 'object' || typeof obj2 !== 'object') return false; const keys1 = Object.keys(obj1); const keys2 = Object.keys(obj2); if (keys1.length !== keys2.length) return false; for (const key of keys1) { if (!customIsEqual(obj1[key], obj2[key])) return false; } return true; } ``` This implementation has the same pros and cons as Lodash's `isEqual`, but it doesn't have the benefit of memoization.
Related benchmarks:
Lodash (v4.17.15) isEqual test
Lodash isEqual compare with custom deepEqual in compare objects
Lodash isEqual test vs strict equality check
Lodash isEqual compare with custom deepEqual in compare objects 1
Comments
Confirm delete:
Do you really want to delete benchmark?