Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
JSON Parse vs StructuredClone bigger object
(version: 0)
Comparses JSON.parse(JSON.stringify()) vs structuredClone on a bigger JSON object
Comparing performance of:
strucutredClone vs JSON.parse(JSON.stringify())
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
var object = { type: "FeatureCollection", features: [{ type: "Feature", properties: {}, geometry: { type: "Point", coordinates: [4.483605784808901, 51.907188449679325] } }, { "type": "Feature", "properties": {}, "geometry": { "type": "Polygon", "coordinates": [ [ [3.974369110811523, 51.907355547778565], [4.173944459020191, 51.86237166892457], [4.3808076710679416, 51.848867725914914], [4.579822414365026, 51.874487141880024], [4.534413416598767, 51.9495302480326], [4.365110733567974, 51.92360787140825], [4.179550508127079, 51.97336560819281], [4.018096293847009, 52.00236546429852], [3.9424146309028174, 51.97681895676649], [3.974369110811523, 51.907355547778565] ] ] } } ] }; var copy = null;
Tests:
strucutredClone
copy = structuredClone(object);
JSON.parse(JSON.stringify())
copy = JSON.parse(JSON.stringify(object));
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
strucutredClone
JSON.parse(JSON.stringify())
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
yesterday
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Safari/537.36
Browser/OS:
Chrome 147 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
strucutredClone
450083.8 Ops/sec
JSON.parse(JSON.stringify())
649506.1 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll break down the provided benchmark definition and explanation of the options being compared. **Benchmark Definition:** The test case is designed to compare the performance of two methods: 1. `structuredClone` (also known as `JSON Structured Clone`) 2. `JSON.parse(JSON.stringify())` Both methods are used to clone a JSON object, but they work differently and have different implications on the original data. **Options being compared:** * **`structuredClone(object);`**: This method creates a new object that is a deep copy of the input object. It is designed to preserve the original structure and properties of the object, including nested objects and arrays. The `structuredClone()` function is part of the ECMAScript 2020 standard. * **`JSON.parse(JSON.stringify(object));`**: This method uses the JSON.stringify() method to serialize the object into a string, and then parses that string back into an object using the JSON.parse() method. While it can achieve the same result as `structuredClone()`, this approach has some limitations and potential issues, such as losing special values like NaN or Infinity. **Pros and Cons:** * **`structuredClone(object);`**: * Pros: + Preserves the original structure and properties of the object. + Supports nested objects and arrays. + Designed for deep copying, which is a common requirement in many applications. * Cons: + May have performance implications due to its recursive nature. * **`JSON.parse(JSON.stringify(object));`**: + Pros: - Simple and straightforward implementation. - Can be faster than `structuredClone()` for small inputs. * Cons: - Loses special values like NaN or Infinity during the cloning process. - Does not preserve the original structure of deeply nested objects. - Can lead to infinite loops if the input object contains circular references. **Library and purpose:** * `structuredClone()`: This function is part of the ECMAScript 2020 standard, which means it's a built-in JavaScript feature. It's designed specifically for deep copying JSON objects, preserving their structure and properties. * `JSON.parse(JSON.stringify(object))`: This method uses two separate functions: `stringify()` to serialize an object into a string, and `parse()` to parse that string back into an object. While it achieves the same result as `structuredClone()`, it's not as efficient or robust. **Special JS features and syntax:** There is no special JavaScript feature or syntax used in this benchmark definition other than `structuredClone()` being compared against `JSON.parse(JSON.stringify())`. However, if you were to modify the input objects to include special values like NaN or Infinity, these would need to be preserved during cloning.
Related benchmarks:
JSON.parse + JSON.stringify vs structuredClone (cyclical graph)
Lodash cloneDeep vs structuredClone vs JSON.parse + JSON.stringify but with big data
JSON.stringify vs structuredClone (with deeply nested objects)
structuredClose(myObject) vs JSON.parse(JSON.stringify(myObject))
Comments
Confirm delete:
Do you really want to delete benchmark?