Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Spread vs JSON.parse(JSON.stringify())
(version: 0)
Benchmarks spread vs JSON.parse(JSON.stringify())
Comparing performance of:
Spread vs JSON Parse & Stringify
Created:
3 years ago
by:
Guest
Jump to the latest result
Tests:
Spread
var theJSON = { "squadName": "Super hero squad", "homeTown": "Metro City", "formed": 2016, "secretBase": "Super tower", "active": true, "members": [ { "name": "Molecule Man", "age": 29, "secretIdentity": "Dan Jukes", "powers": [ "Radiation resistance", "Turning tiny", "Radiation blast" ] }, { "name": "Madame Uppercut", "age": 39, "secretIdentity": "Jane Wilson", "powers": [ "Million tonne punch", "Damage resistance", "Superhuman reflexes" ] }, { "name": "Eternal Flame", "age": 1000000, "secretIdentity": "Unknown", "powers": [ "Immortality", "Heat Immunity", "Inferno", "Teleportation", "Interdimensional travel" ] } ] } var result = {...theJSON}
JSON Parse & Stringify
var theJSON = { "squadName": "Super hero squad", "homeTown": "Metro City", "formed": 2016, "secretBase": "Super tower", "active": true, "members": [ { "name": "Molecule Man", "age": 29, "secretIdentity": "Dan Jukes", "powers": [ "Radiation resistance", "Turning tiny", "Radiation blast" ] }, { "name": "Madame Uppercut", "age": 39, "secretIdentity": "Jane Wilson", "powers": [ "Million tonne punch", "Damage resistance", "Superhuman reflexes" ] }, { "name": "Eternal Flame", "age": 1000000, "secretIdentity": "Unknown", "powers": [ "Immortality", "Heat Immunity", "Inferno", "Teleportation", "Interdimensional travel" ] } ] } var result = JSON.parse(JSON.stringify(theJSON))
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Spread
JSON Parse & Stringify
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
5 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:145.0) Gecko/20100101 Firefox/145.0
Browser/OS:
Firefox 145 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Spread
14733271.0 Ops/sec
JSON Parse & Stringify
566962.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Benchmark Explanation** The provided benchmark measures the performance difference between two approaches: using the spread operator (`...`) to create a shallow copy of an object, and using `JSON.parse(JSON.stringify())` to create a deep copy of an object. **Options Compared** Two options are compared: 1. **Spread Operator (```...``)**: This method creates a new object by copying selected properties from an existing object. 2. **JSON.parse(JSON.stringify())**: This method creates a deep copy of an object by recursively copying all its properties, including nested objects and arrays. **Pros and Cons** * **Spread Operator (```...``)** + Pros: Fast, efficient, and concise way to create a shallow copy of an object. + Cons: Only creates a shallow copy, which means it only copies the top-level properties of an object. If the original object has nested objects or arrays, those will be referenced in the copied object instead of being cloned. * **JSON.parse(JSON.stringify())** + Pros: Creates a deep copy of an object, ensuring that all nested objects and arrays are properly cloned. + Cons: Slower than the spread operator due to the recursive nature of JSON parsing. **Library/Functionality Used** In this benchmark, `JSON.parse(JSON.stringify())` is used from the built-in JavaScript `JSON` object. This function is a standard part of the language and does not require any external libraries or dependencies. **Special JS Feature/Syntax** There are no special JS features or syntax used in this benchmark other than the use of the spread operator (`...`) and the `JSON.parse(JSON.stringify())` method. **Other Alternatives** If you need to create a deep copy of an object, you can also use libraries like Lodash's `cloneDeep()` function or a recursive function that clones all properties of an object. However, these alternatives are not part of the standard JavaScript language and require additional dependencies. In summary, this benchmark measures the performance difference between two approaches for creating shallow copies of objects: using the spread operator (`...`) versus using `JSON.parse(JSON.stringify())`. The choice of approach depends on your specific use case and whether you need a deep copy of an object.
Related benchmarks:
Spread operator vs array push
String.proptotype.split vs spread operator
spread operator vs push test - correct
JS array spread operator vs push
JSON.parse vs string.splitn
Comments
Confirm delete:
Do you really want to delete benchmark?