Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash isEqual test 6 levels
(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 6 vs JSON.stringify Level 6
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 = { 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 } } }; // 6 levels deep window.foo3 = { a: 1, b: 2, c: { a: 1, b: 2, c: { 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, c: { a: 1, b: 2, c: { a: 1, b: 2 } }} } };
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 6
_.isEqual(window.foo3, window.bar3)
JSON.stringify Level 6
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 6
JSON.stringify Level 6
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 world of JavaScript microbenchmarks on MeasureThat.net. **Benchmark Overview** The provided benchmark tests the performance of two approaches to compare objects for equality: 1. Using the `_.isEqual` function from the Lodash library. 2. Using JSON stringification and comparison. **Options Compared** There are six test cases that compare these two approaches, with different levels of nesting in the objects being compared: * Level 1: Two shallowly nested objects (`foo1` and `bar1`) * Level 2: Two deeply nested objects (`foo2` and `bar2`) with one level of nesting * Level 6: Two very deeply nested objects (`foo3` and `bar3`) with six levels of nesting **Pros and Cons of Each Approach** ### _.isEqual * **Advantages:** + Faster, as it doesn't require creating a JSON string. + More efficient for large objects, as it can take advantage of caching and memoization. + Less prone to errors due to the simplicity of the comparison logic. * **Disadvantages:** + May not be as accurate in certain edge cases (e.g., when comparing NaN values). + Requires Lodash library, which may introduce an additional dependency. ### JSON Stringification * **Advantages:** + More accurate for comparing objects with complex nested structures. + Easier to understand and debug, as the comparison is more straightforward. * **Disadvantages:** + Slower, as creating a JSON string requires additional overhead. + More prone to errors due to the complexity of the stringification process. **Other Considerations** * The `_.isEqual` function uses a combination of object property checks and prototype chain traversal to compare objects. This approach can be less efficient for very large or complex objects, as it may require traversing deeper into the object's prototype chain. * JSON stringification creates an additional layer of indirection between the original object and its representation as a string. While this allows for more accurate comparisons, it also introduces an extra step that can slow down performance. **Library: Lodash** The `_.isEqual` function is part of the Lodash library, which provides a collection of utility functions for JavaScript developers. While Lodash is not required to write JavaScript code, using its functions can simplify certain tasks and make code more concise. Overall, the choice between using `_isEqual` or JSON stringification depends on the specific requirements of your project. If you need to compare objects with complex nested structures, JSON stringification might be a better choice. However, if you're working with large datasets or performance-critical code, `_.isEqual` could provide a faster and more efficient solution.
Related benchmarks:
Lodash (v4.17.15) isEqual test
Lodash isEqual test 4.17.15
Lodash isEqual compare with custom deepEqual in compare objects
Lodash isEqual test vs strict equality check
Lodash isEqual Array of Objects test
Comments
Confirm delete:
Do you really want to delete benchmark?