Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Fast deep equal vs JSON.stringify
(version: 0)
Comparing performance of:
JSON.stringify vs fast equal
Created:
2 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/fast-equals@5.0.1/dist/min/index.js"></script>
Script Preparation code:
// 1 level deep var data = [ { description: 'equal numbers', value1: 1, value2: 1, equal: true, }, { description: 'not equal numbers', value1: 1, value2: 2, equal: false, }, { description: 'number and array are not equal', value1: 1, value2: [], equal: false, }, { description: '0 and null are not equal', value1: 0, value2: null, equal: false, }, { description: 'equal strings', value1: 'a', value2: 'a', equal: true, }, { description: 'big object', value1: { prop1: 'value1', prop2: 'value2', prop3: 'value3', prop4: { subProp1: 'sub value1', subProp2: { subSubProp1: 'sub sub value1', subSubProp2: [ 1, 2, { prop2: 1, prop: 2 }, 4, 5, ], }, }, prop5: 1000, prop6: new Date(2016, 2, 10), }, value2: { prop5: 1000, prop3: 'value3', prop1: 'value1', prop2: 'value2', prop6: new Date('2016/03/10'), prop4: { subProp2: { subSubProp1: 'sub sub value1', subSubProp2: [ 1, 2, { prop2: 1, prop: 2 }, 4, 5, ], }, subProp1: 'sub value1', }, }, equal: true, }, ];
Tests:
JSON.stringify
data.forEach((item) => { JSON.stringify(item.value1) === JSON.stringify(item.value2); });
fast equal
data.forEach((item) => { window["fast-equals"].deepEqual(item.value1, item.value2); });
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
JSON.stringify
fast equal
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
4 months ago
)
User agent:
Mozilla/5.0 (Android 12; Mobile; rv:146.0) Gecko/146.0 Firefox/146.0
Browser/OS:
Firefox Mobile 146 on Android
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
JSON.stringify
140268.5 Ops/sec
fast equal
292432.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Overview** MeasureThat.net is a website that allows users to create and run JavaScript microbenchmarks. The provided JSON represents two benchmark definitions, each with its own test cases. We'll break down what's being tested, the pros and cons of different approaches, and discuss any special libraries or syntax used. **Benchmark Definitions** There are two benchmark definitions: 1. **Fast deep equal vs JSON.stringify**: This benchmark compares the performance of using `JSON.stringify()` and a custom "fast-equals" library to check for deep equality between two objects. 2. **JSON.stringify**: This benchmark measures the performance of simply using `JSON.stringify()` to compare two objects. **Script Preparation Code** The script preparation code defines an array `data` with various test cases, each containing different values and expected outcomes for equality checks. **Html Preparation Code** The HTML preparation code includes a script tag that loads the "fast-equals" library, which is used in one of the benchmark definitions. **Individual Test Cases** There are two individual test cases: 1. **JSON.stringify**: This test case uses `JSON.stringify()` to compare each value in the `data` array with its corresponding value in another object. 2. **Fast equal**: This test case uses the "fast-equals" library's `deepEqual()` method to check for deep equality between each value in the `data` array and its corresponding value in another object. **Pros and Cons** Here are some pros and cons of using `JSON.stringify()` versus a custom equality checking library like "fast-equals": * **JSON.stringify()**: + Pros: Simple, widely supported, and efficient for simple equality checks. + Cons: Can be slow and memory-intensive for large objects or complex data structures. + Potential issues: May not work correctly with certain types of data (e.g., dates, numbers) or edge cases (e.g., NaN, Infinity). * **Fast-equals library**: + Pros: Optimized for performance, supports deep equality checks, and handles various edge cases. + Cons: Requires an additional library download and may have smaller community support compared to built-in `JSON.stringify()`. **Other Alternatives** If you're looking for alternative libraries or approaches for equality checking, consider: * **Lodash's `isEqual()`**: A popular utility library that provides a comprehensive equality checking function. * **Object.is()**: A modern browser API that can be used for simple equality checks. * **Deep-Equals**: Another popular library specifically designed for deep equality checks. **Special Syntax and Libraries** The "fast-equals" library uses a custom syntax to define the `deepEqual()` method, which is not part of standard JavaScript. This allows for more efficient and flexible equality checking compared to using `JSON.stringify()` alone.
Related benchmarks:
Check my data 2
Lodash.isEqual vs JSON.stringify Equality Comparison for deeply nested objects.
Lodash.isEqual vs JSON.stringify Equality Comparison for Object
Lodash.isEqual vs JSON.stringify Equality Comparison for array of objects with nested properties and lots of records 222weqeqrq
JSON Stringify ICX
Comments
Confirm delete:
Do you really want to delete benchmark?