Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash isEqual test with big objects2
(version: 0)
Test on isEqual performance
Comparing performance of:
_.isEqual Level 3 vs JSON.stringify Level 3 vs object test
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:
// 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 } } }; // 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);
object test
_.isEqual(window.test1, window.test2)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
_.isEqual Level 3
JSON.stringify Level 3
object test
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 and explain what's being tested. **Benchmark Definition** The benchmark is designed to measure the performance of the `_.isEqual` function from Lodash, which is a utility library for JavaScript. The test cases are created using two objects: `window.test1` and `window.test2`. These objects have nested structures with similar properties but different values at certain levels. **Options Compared** The benchmark tests three different approaches to compare the equality of these two objects: 1. **_.isEqual**: This is the built-in Lodash function that checks for deep object equality. 2. **JSON.stringify**: This method converts an object into a JSON string and then compares the resulting strings using the `===` operator. **Pros and Cons** * _.isEqual: + Pros: Fast, accurate, and well-tested. + Cons: May not work correctly with complex data structures or circular references. * JSON.stringify: + Pros: Simple to implement, works well for simple objects. + Cons: Can be slow, may not work correctly with complex data structures or circular references. **Other Considerations** In addition to these two approaches, there are other ways to compare object equality in JavaScript, such as: 1. **Object.entries().every()**: This method iterates over the entries of an object and checks if they match a certain value. 2. **For...in loops**: This approach uses loops to iterate over the properties of an object and checks for equality. However, these methods are generally less efficient and less accurate than _.isEqual or JSON.stringify. **Latest Benchmark Result** The latest benchmark result shows that: * Firefox 107 performs best with a rate of 147289.515625 executions per second. * The next best results come from the **object test**, which has a rate of 63412.953125 executions per second. * The _.isEqual Level 3 test has the slowest result, with a rate of 62986.47265625 executions per second. Overall, this benchmark highlights the importance of choosing the right approach to compare object equality in JavaScript, depending on the specific use case and performance requirements.
Related benchmarks:
Normal for loop vs JSON.stringify to detect Inequality for Array of Objects.
Lodash.isEqual vs JSON.stringify Equality Comparison for deep objects.
Lodash.isEqual vs JSON.stringify Equality Comparison for objects
Lodash vs. direct comparison
Lodash.isEqual vs Lodash.isEqualWith Equality Comparison for Shallow Array of Strings.
Comments
Confirm delete:
Do you really want to delete benchmark?