Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash.isEqual vs JSON.stringify 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
Created:
4 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);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
_.isEqual
JSON.stringify
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36
Browser/OS:
Chrome 135 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
_.isEqual
10057156.0 Ops/sec
JSON.stringify
692219.6 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and explain what's being tested. **Benchmark Overview** The benchmark compares the performance of two approaches: `_.isEqual` from Lodash and a direct comparison using `JSON.stringify`. **What is being tested?** The test case uses an array of objects (`window.foo`) with nested properties and lots of records. The goal is to determine which approach is faster for comparing two arrays or objects with similar structure. **Options compared:** 1. **Lodash's _.isEqual**: A utility function that recursively compares the structure of two values. 2. **Direct Comparison using `JSON.stringify`**: A simple comparison that converts both values to JSON strings and checks if they are equal. **Pros and Cons of each approach:** 1. **_.isEqual (Lodash)**: * Pros: More flexible, can handle nested objects with complex structures, and is designed for deep comparisons. * Cons: May be slower due to recursive function calls, and its performance can degrade for very large datasets. 2. **Direct Comparison using `JSON.stringify`**: * Pros: Fast and lightweight, easy to implement, and works well for simple cases. * Cons: May not work correctly for complex nested objects or arrays with missing values. **Other considerations:** * The benchmark uses a custom JavaScript environment (MeasureThat.net) that may introduce additional overhead or differences in performance compared to other environments. * The use of `window.foo` and `window.bar` as test data is likely due to the need to create a large dataset for testing. In a real-world scenario, this would typically be done using a more controlled and repeatable method. **Library:** The benchmark uses Lodash (`_`) as a library. Lodash provides a set of utility functions for functional programming, including `isEqual`, which is used in the test case. **Special JavaScript feature or syntax:** None mentioned in this benchmark. Now, let's discuss alternatives: * **Alternative 1:** Use a different comparison library, such as Moment.js or Recurse.js, that might offer better performance or features for specific use cases. * **Alternative 2:** Implement the direct comparison using `JSON.stringify` in-house, which could potentially improve performance if optimized correctly. * **Alternative 3:** Compare the results of both approaches with additional metrics, such as memory usage or error rates, to get a more comprehensive understanding of their trade-offs. Keep in mind that these alternatives would require significant modifications to the benchmark and may not be worth pursuing unless there are specific requirements or constraints that necessitate change.
Related benchmarks:
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
Lodash.isEqual vs JSON.stringify and recusive Equality Comparison for array of objects with nested properties and lots of records
Comments
Confirm delete:
Do you really want to delete benchmark?