Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
es-toolkit isEqual vs JSON stringify
(version: 2)
Comparing performance of:
es-toolkit vs JSON.stringify
Created:
one year ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/es-toolkit@%5E1"></script>
Script Preparation code:
const node1 = { id: "n-w71cvCJS6w7WM8E3C3_6w", order: "a06DJ", type: "shape", attributes: { width: 100, height: 100, color: '#fff', } }; const node2 = { id: "n-w71cvCJS6w7WM8E3C3_6w", order: "a06DJ", type: "shape", attributes: { width: 100, height: 100, color: '#fff', } };
Tests:
es-toolkit
_.isEqual(node1, node2);
JSON.stringify
JSON.stringify(node1) === JSON.stringify(node2);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
es-toolkit
JSON.stringify
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
3 months ago
)
User agent:
Mozilla/5.0 (iPhone; CPU iPhone OS 26_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Brave/1 Mobile/15E148 Safari/604.1
Browser/OS:
Mobile Safari 26 on iOS 26.2
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
es-toolkit
2940453.0 Ops/sec
JSON.stringify
5679867.5 Ops/sec
Autogenerated LLM Summary
(model
gpt-4o-mini
, generated one year ago):
The benchmark provided compares two methods of determining if two JavaScript objects (`node1` and `node2`) are equal in value. The two different approaches are evaluated to see which is more performant. ### Approaches Compared 1. **es-toolkit's `_.isEqual` Method**: - **Function**: This method comes from the `es-toolkit` library, which is a utility library designed to provide various utility functions for working with JavaScript data structures. The `isEqual` function checks for deep equality between two values, meaning it will traverse objects and arrays to determine if they are equivalent in terms of structure and content. - **Pros**: - Handles deep comparison effectively. - Can differentiate between complex data structures. - The flexible nature allows for nuanced comparisons of nested objects. - **Cons**: - Typically slower than shallow comparisons due to the need to inspect every property recursively. - May introduce overhead from the utility library itself. 2. **JSON.stringify Method**: - **Function**: This approach uses `JSON.stringify` to convert both `node1` and `node2` into JSON string representations, then compares the resulting strings for equality. This method works well for simple structures that can be serialized into JSON format. - **Pros**: - Generally faster, especially for simple objects, since string comparison is less computationally intensive than deep equality checks using an algorithm. - Simple approach with no extra dependencies (uses built-in JavaScript functions). - **Cons**: - Fails for objects that contain methods or properties that cannot be serialized into JSON (e.g., functions, undefined, or circular references). - May produce incorrect results if the order of properties is different, even if the overall structure and values are the same. ### Benchmark Results The benchmark results show that `JSON.stringify` outperforms `es-toolkit`'s `_.isEqual`. Specifically: - `JSON.stringify`: 3,298,864.75 executions per second. - `es-toolkit`: 2,184,983.75 executions per second. This indicates that, at least for the given test cases and the structures provided, the stringification method offers better performance. ### Other Considerations - **Edge Cases**: Developers should consider the types of data they are comparing. If the comparison needs to handle complex objects (objects with methods, circular references, etc.), the `es-toolkit` function is more appropriate despite its performance cost. - **Alternatives to Consider**: - **Shallow Comparison**: For simpler objects where only the top-level properties matter, a shallow comparison using strict equality checks may suffice and would be much faster. - **Lodash's `_.isEqual`**: Another utility library, Lodash, has a similar `isEqual` function that many developers use. Results may vary by implementation, so testing would be needed. - **Custom Comparison Functions**: Depending on specific requirements, writing a custom function tailored to the structure of the data being compared can yield performance benefits. This evaluation can help developers decide on the appropriate method of value comparison in their applications based on performance considerations and the nature of the data being handled.
Related benchmarks:
aaaaaa
Lodash clone deep performance
Lodash.isEqual vs JSON.stringify fort object
asdsadadasdad55
JSON.stringify vs structuredClone more
JSON.stringify vs structuredClone list
lodash vs JSON22
test json vs omit
JSON.stringify vs structuredClone fork
Comments
Confirm delete:
Do you really want to delete benchmark?