Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash isEqual test array of objects
(version: 0)
Test on isEqual performance
Comparing performance of:
_.isEqual Level 1 vs JSON.stringify Level 1
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:
// 1 level deep window.foo1 = [ {id: "1035257027", person_id: "1043549930", group_id: "551225445", avatar_url: "http://people.pco.test/static/no_photo_thumbnail_gray.png", email_address: "pico@pco.bz"}, {id: "1035257027", person_id: "1043549930", group_id: "551225445", avatar_url: "http://people.pco.test/static/no_photo_thumbnail_gray.png", email_address: "pico@pco.bz"}, ]; window.bar1 = [ {id: "1035257027", person_id: "1043549930", group_id: "551225445", avatar_url: "http://people.pco.test/static/no_photo_thumbnail_gray.png", email_address: "pico@pco.bz"}, {id: "1035257025", person_id: "1043549930", group_id: "551225445", avatar_url: "http://people.pco.test/static/no_photo_thumbnail_gray.png", email_address: "pico@pco.bz"}, ];
Tests:
_.isEqual Level 1
_.isEqual(window.foo1, window.bar1)
JSON.stringify Level 1
JSON.stringify(window.foo1) === JSON.stringify(window.bar1);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
_.isEqual Level 1
JSON.stringify Level 1
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
3 months ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36
Browser/OS:
Chrome 133 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
_.isEqual Level 1
1058994.5 Ops/sec
JSON.stringify Level 1
1489547.1 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks on MeasureThat.net. The provided benchmark definition and individual test cases are used to measure the performance of the `isEqual` function from the Lodash library. Here's what's being tested: 1. **Lodash isEqual**: The `isEqual` function is a utility function that checks if two objects or arrays are deeply equal. It's used to compare complex data structures, such as nested objects and arrays. 2. **Options comparison**: Two options are compared: * Using the Lodash `isEqual` function (`_.isEqual(window.foo1, window.bar1)`). * Using a simple string comparison with `JSON.stringify()` (`JSON.stringify(window.foo1) === JSON.stringify(window.bar1)`). **Pros and Cons:** * **Lodash isEqual**: + Pros: - Handles complex data structures, such as nested objects and arrays. - Provides a flexible way to compare objects and arrays. + Cons: - May be slower due to the overhead of the Lodash library. - Can be affected by the complexity of the input data. * **Simple string comparison with JSON.stringify()**: + Pros: - Fast and lightweight, as it only requires basic string comparison. - Does not rely on a external library like Lodash. + Cons: - May not handle complex data structures correctly. - Can be affected by issues with `JSON.stringify()` implementation. **Library:** The Lodash library is a popular utility library for JavaScript that provides a wide range of functions for tasks such as array manipulation, object transformation, and more. In this case, the `isEqual` function is used to compare complex data structures. **Special JS feature or syntax:** None mentioned in the provided benchmark definition. However, note that the use of `window.foo1` and `window.bar1` suggests a global variable context, which may not be representative of typical web development scenarios where variables are scoped to functions or modules. **Other alternatives:** If you want to compare two objects or arrays without using Lodash, you can consider implementing your own equality check function. Here's an example: ```javascript function isEqual(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 (!isEqual(obj1[key], obj2[key])) return false; } return true; } ``` Alternatively, you can use a library like `fast-json-stable-stringify` or `json-stable-stringify` to compare JSON strings. Keep in mind that the choice of equality check function depends on your specific use case and performance requirements.
Related benchmarks:
Lodash.isEqual vs Array.join('') Equality Comparison for Shallow Array of Strings.
Lodash.isEqual vs Array.join() Equality Comparison for Shallow Array of Strings.
_.isEmpty vs 3 array.length 2
_.isEmpty vs 3 array.length 3
Lodash.isEqual vs Lodash.isEqualWith Equality Comparison for Shallow Array of Strings.
Comments
Confirm delete:
Do you really want to delete benchmark?