Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
Feature Requests
FAQ
Register
Log In
Lodash isEqual vs JSON.stringify test with big objects
(version: 0)
Benchmark.js
Test on isEqual vs JSON.stringify performance
Comparing performance of:
_.isEqual Level 3 vs JSON.stringify Level 3
Created:
3 years ago
by:
Guest
Go 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.test1 = { "traffic": "POPUP", "targeting": { "BASE": { "adultFilters": [ "ADULT", "NON_ADULT" ], "deviceFilters": { "devices": [ "MOBILE" ], "networks": { "type": "ALL" }, "desktopOses": [], "mobileOses": [ { "os": "ANDROID_PHONE", "version": { "min": "MIN", "max": "MAX" } }, { "os": "IOS_TABLET", "version": { "min": "MIN", "max": "MAX" } }, { "os": "OTHER", "version": { "min": "MIN", "max": "MAX" } }, { "os": "ANDROID_TABLET", "version": { "min": "MIN", "max": "MAX" } }, { "os": "IOS_PHONE", "version": { "min": "MIN", "max": "MAX" } } ], "desktopBrowsers": [], "mobileBrowsers": [ "FACEBOOK", "FIREFOX", "CHROME", "SAFARI", "OPERA", "UC_BROWSER", "ANDROID", "OTHER", "SAMSUNG" ] } }, "GEO": { "country": { "code": "US" } } } } window.test2 = { "traffic": "POPUP", "targeting": { "BASE": { "adultFilters": [ "ADULT", "NON_ADULT" ], "deviceFilters": { "devices": [ "MOBILE" ], "networks": { "type": "ALL" }, "desktopOses": [], "mobileOses": [ { "os": "ANDROID_PHONE", "version": { "min": "MIN", "max": "MAX" } }, { "os": "IOS_TABLET", "version": { "min": "MIN", "max": "MAX" } }, { "os": "OTHER", "version": { "min": "MIN", "max": "MAX" } }, { "os": "ANDROID_TABLET", "version": { "min": "MIN", "max": "MAX" } }, { "os": "IOS_PHONE", "version": { "min": "MIN", "max": "MAX" } } ], "desktopBrowsers": [], "mobileBrowsers": [ "FACEBOOK", "FIREFOX", "CHROME", "SAFARI", "OPERA", "UC_BROWSER", "ANDROID", "OTHER", "SAMSUNG" ] } }, "GEO": { "country": { "code": "US" } } } }
Tests:
_.isEqual Level 3
_.isEqual(window.test1, window.test2)
JSON.stringify Level 3
JSON.stringify(window.test1) === JSON.stringify(window.test2);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
_.isEqual Level 3
JSON.stringify Level 3
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36
Browser/OS:
Chrome 130 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
JSON.stringify Level 3
444K/s
_.isEqual Level 3
185K/s
View exact numbers
Test name
Executions per second
✓
JSON.stringify Level 3
444,108 Ops/sec
_.isEqual Level 3
184,510 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks! **Benchmark Definition** The provided JSON represents a benchmarking test case for comparing the performance of two methods: `_.isEqual` from the Lodash library and `JSON.stringify` with a comparison operator (`===`). The test creates two objects, `window.test1` and `window.test2`, which are then compared using these two different approaches. **What's being tested** The benchmark is testing the following: * **`.isEqual` vs. `JSON.stringify`**: This test compares the performance of Lodash's `_.isEqual` function, which checks for deep object equality, against the traditional approach of using `JSON.stringify` with a comparison operator (`===`). The question is: which method is faster and more efficient? **Options compared** The benchmark is comparing two options: 1. **`.isEqual` (Lodash)**: This function checks for deep object equality, taking into account all properties, arrays, and objects. 2. **`JSON.stringify` with `===`**: This approach converts both objects to JSON strings using `JSON.stringify`, and then compares the resulting strings using a strict equality operator (`===`). This method can be slower because it involves converting the objects to strings, which may not be necessary for comparison. **Pros and Cons of each approach** * **`.isEqual (Lodash)`** + Pros: - More efficient than `JSON.stringify` with `===`, as it only checks for deep equality without converting to strings. - Can handle complex object comparisons more effectively, including arrays and objects. + Cons: - May be slower in certain cases where the comparison only requires checking a small subset of properties. * **`JSON.stringify` with `===`** + Pros: - Simple and straightforward implementation. + Cons: - Slower due to the conversion to strings, which may not be necessary for comparison. - May not handle complex object comparisons as effectively as `.isEqual`. **Library used** The benchmark uses the Lodash library (`lodash.min.js`), specifically the `_.isEqual` function. **Special JS feature/syntax** This benchmark does not use any special JavaScript features or syntax. It only relies on standard JavaScript objects and functions. **Alternatives** If you're looking for alternatives to `.isEqual`, you might consider using other deep comparison libraries like `deep-equal` or `fast-deep-equal`. However, the choice of library ultimately depends on your specific use case and performance requirements. Now that we've explored the benchmarking test case, I hope this explanation has provided a solid understanding of what's being tested!
Related benchmarks
Lodash.isEqual vs JSON.stringify Equality Comparison for Plain Objects
Lodash.isEqual vs JSON.stringify Equality Comparison for Small Objects.
Comments
Confirm delete:
Do you really want to delete benchmark?