Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash.isEqual vs JSON.stringify and recusive Equality Comparison for array of objects with nested properties and lots of records
(version: 0)
Test on isEqual performance
Comparing performance of:
_.isEqual vs JSON.stringify vs recusive native
Created:
3 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:
window.foo = [{accessPath: 'derp.merp', ancestors: ['blah', 'blah']}, {accessPath: 'derp.merp', ancestors: ['blah', 'blah']}, {accessPath: 'derp.merp', ancestors: ['blah', 'blah']}, {accessPath: 'derp.merp', ancestors: ['blah', 'blah']}, {accessPath: 'derp.merp', ancestors: ['blah', 'blah']}, {accessPath: 'derp.merp', ancestors: ['blah', 'blah']}, {accessPath: 'derp.merp', ancestors: ['blah', 'blah']}, {accessPath: 'derp.merp', ancestors: ['blah', 'blah']}, {accessPath: 'derp.merp', ancestors: ['blah', 'blah']}, {accessPath: 'derp.merp', ancestors: ['blah', 'blah']}, {accessPath: 'derp.merp', ancestors: ['blah', 'blah']}, {accessPath: 'merp', ancestors: ['blah', 'merp']}, {accessPath: 'derp', ancestors: ['blah', 'derp']}]; window.foo = [{accessPath: 'derp.merp', ancestors: ['blah', 'blah']}, {accessPath: 'derp.merp', ancestors: ['blah', 'blah']}, {accessPath: 'derp.merp', ancestors: ['blah', 'blah']}, {accessPath: 'derp.merp', ancestors: ['blah', 'blah']}, {accessPath: 'derp.merp', ancestors: ['blah', 'blah']}, {accessPath: 'derp.merp', ancestors: ['blah', 'blah']}, {accessPath: 'derp.merp', ancestors: ['blah', 'blah']}, {accessPath: 'derp.merp', ancestors: ['blah', 'blah']}, {accessPath: 'derp.merp', ancestors: ['blah', 'blah']}, {accessPath: 'derp.merp', ancestors: ['blah', 'blah']}, {accessPath: 'derp.merp', ancestors: ['blah', 'blah']}, {accessPath: 'merp', ancestors: ['blah', 'merp']}, {accessPath: 'derp', ancestors: ['blah', 'changed']}];
Tests:
_.isEqual
_.isEqual(window.foo, window.bar)
JSON.stringify
JSON.stringify(window.foo) === JSON.stringify(window.bar);
recusive native
function deepEqual(obj1, obj2) { if (obj1 === obj2) { return true; // If both objects are strictly equal, they are deeply equal } if (typeof obj1 !== 'object' || obj1 === null || typeof obj2 !== 'object' || obj2 === null) { return false; // If either object is not an object or null, they are not deeply equal } const keys1 = Object.keys(obj1); const keys2 = Object.keys(obj2); if (keys1.length !== keys2.length) { return false; // If the objects have different number of keys, they are not deeply equal } for (let key of keys1) { if (!obj2.hasOwnProperty(key) || !deepEqual(obj1[key], obj2[key])) { return false; // If the values of a key are not deeply equal, the objects are not deeply equal } } return true; // If all keys and values are deeply equal, the objects are deeply equal } deepEqual(window.foo, window.bar)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
_.isEqual
JSON.stringify
recusive native
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 break down the provided benchmark definition and explain what is being tested. **What is being tested:** The benchmark tests the performance of three different approaches to compare two objects: 1. `_.isEqual` (from Lodash library) 2. `JSON.stringify` with recursive equality comparison 3. A custom implementation of deep equality comparison (`deepEqual` function) **Options compared:** * **Lodash _.isEqual**: This is a widely used library function that checks if two values are equal using a deep equality algorithm. * **JSON.stringify and recursive equality comparison**: This approach uses the `JSON.stringify` method to convert objects into JSON strings, which can be compared for equality. The test also implements a custom recursive equality comparison function (`deepEqual`) to handle nested properties and arrays. * **Custom implementation of deep equality comparison (`deepEqual` function)**: This is a custom implementation that checks if two objects have the same structure and values using a recursive approach. **Pros and Cons of each approach:** * **Lodash _.isEqual**: Pros: + Widely used and well-maintained library + Optimized for performance + Easy to use and understand * Cons: + May not be suitable for very large or complex objects due to memory constraints + May not work correctly with certain types of data (e.g., null, undefined) * **JSON.stringify and recursive equality comparison**: + Pros: - Easy to implement and understand - Can handle large and complex objects + Cons: - Slower than Lodash _.isEqual due to the overhead of JSON serialization - May not work correctly with certain types of data (e.g., circular references) * **Custom implementation of deep equality comparison (`deepEqual` function)**: + Pros: - Can be optimized for specific use cases and performance requirements - Provides fine-grained control over the comparison process + Cons: - Requires manual implementation and maintenance - May require more development time and expertise **Other considerations:** * **Performance**: The benchmark measures the execution speed of each approach, which is essential for high-performance applications. * **Memory usage**: The benchmark also considers memory usage, as it tests large objects with many nested properties. **Alternatives to Lodash _.isEqual:** * Other deep equality libraries (e.g., `deep-equal`, `fast-deep-equal`) * Custom implementations of deep equality comparison * Other stringification approaches (e.g., using a custom implementation instead of `JSON.stringify`) Overall, the benchmark provides a comprehensive comparison of three different approaches to compare objects, allowing users to choose the best approach for their specific use case and performance requirements.
Related benchmarks:
Lodash.isEqual vs JSON.stringify Equality Comparison for array of objects with nested properties and lots of records
Lodash.isEqual vs JSON.stringify Equality Comparison for array of objects with nested properties and many records
Lodash.isEqual vs JSON.stringify Equality Comparison for array of objects with nested properties and few records
Lodash.isEqual vs JSON.stringify Equality Comparison for array of objects with nested properties and lots of records 222weqeqrq
Comments
Confirm delete:
Do you really want to delete benchmark?