Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
my isEqual
(version: 0)
Test on isEqual performance
Comparing performance of:
_.isEqual Level 1 vs isEqual Level 1 vs _.isEqual Level 2 vs isEqual Level 2 vs _.isEqual Level 3 vs isEqual Level 3
Created:
5 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> function isEqual(a, b) { var aProps = Object.getOwnPropertyNames(a) , bProps = Object.getOwnPropertyNames(b); if (aProps.length != bProps.length) { return false; } for (var i = 0; i < aProps.length; i++) { var propName = aProps[i]; if (typeof(a[propName]) === 'object' && a[propName] !== null) { if (!isEqual(a[propName], b[propName])) { return false } } else if (Number.isNaN(a[propName])) { if (!Number.isNaN(b[propName])) { return false } } else if (a[propName] !== b[propName]) { return false; } } return true; } </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 } } };
Tests:
_.isEqual Level 1
_.isEqual(window.foo1, window.bar1)
isEqual Level 1
isEqual(window.foo1, window.bar1)
_.isEqual Level 2
_.isEqual(window.foo2, window.bar2)
isEqual Level 2
isEqual(window.foo2, window.bar2)
_.isEqual Level 3
_.isEqual(window.foo3, window.bar3)
isEqual Level 3
isEqual(window.foo3, 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
isEqual Level 1
_.isEqual Level 2
isEqual Level 2
_.isEqual Level 3
isEqual Level 3
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):
I'll break down the provided benchmark and explain what's being tested, compared options, pros and cons of each approach, library usage, and special JavaScript features. **Benchmark Overview** The benchmark tests the performance of two equality functions: `isEqual` (from Lodash) and a custom implementation. The test cases create complex objects with nested properties to exercise the equality function. **Test Cases** There are four test cases: 1. `_.isEqual(window.foo1, window.bar1)` (Level 1) 2. `_.isEqual(window.foo2, window.bar2)` (Level 2) 3. `_.isEqual(window.foo3, window.bar3)` (Level 3) These tests compare two objects at each level of nesting: * Level 1: Two objects with different properties * Level 2: Two objects with similar but not identical properties * Level 3: Two objects with identical properties **Custom Implementation** The custom `isEqual` function is implemented using recursion, which makes it easy to see how the code compares the two input objects. The implementation checks for: * Object property names (using `Object.getOwnPropertyNames`) * Property types and values * Object structure (nested objects) While the custom implementation works, it may not be as efficient as the Lodash version. **Lodash Library** The benchmark uses the Lodash library to provide a pre-existing implementation of the `isEqual` function. Lodash is a popular utility library that provides various functions for data manipulation and analysis. **Comparison Options** There are two main comparison options: 1. **_.isEqual (Lodash)**: The optimized, pre-built equality function from Lodash. 2. **Custom Implementation**: A custom implementation of the `isEqual` function using recursion. **Pros and Cons** * _.isEqual: + Pros: - Optimized for performance - Well-tested and maintained + Cons: - Not easily modifiable (unless you're a Lodash maintainer) - May not be suitable for all use cases (e.g., specific industry requirements) * Custom Implementation: + Pros: - Highly customizable - Easy to understand and maintain + Cons: - May be slower than the optimized _.isEqual implementation **Special JavaScript Features** There are no special JavaScript features used in this benchmark, but some minor optimizations might be applicable: * Using `Object.keys()` instead of `Object.getOwnPropertyNames` for a small performance boost. * Considering using a library like `fast-json-stamp` for faster JSON serialization. Overall, the benchmark provides a clear comparison between two equality functions: an optimized Lodash implementation and a custom recursive implementation. This allows users to choose the best fit for their specific use case, considering factors such as performance, customization options, and maintainability.
Related benchmarks:
Lodash (v4.17.15) isEqual test
Lodash isEqual compare with custom deepEqual in compare objects
Lodash isEqual test vs strict equality check
Lodash isEqual Array of Objects test
Lodash isEqual compare with custom deepEqual in compare objects 1
Comments
Confirm delete:
Do you really want to delete benchmark?