array structuredClone vs. JSON.parse/stringify vs. map

Benchmark created on


Setup

const myObj = {
  description: 'Creates a deep copy of source, which should be an object or an array.',
  myNumber: 123456789,
  myBoolean: true,
  jayson: {
    stringify: 'JSON.stringify() method converts a JavaScript value to a JSON string....',
    parse: 'JSON.parse() method parses a JSON string...'
  },
  myArr: [1,2,3]
};

const arr = [{...myObj}, {...myObj}, {...myObj}];

Test runner

Ready to run.

Testing in
TestOps/sec
structuredClone
const myCopy = structuredClone(arr)
ready
JSON
const myCopy = JSON.parse(JSON.stringify(arr))
ready
map
const myCopy = arr.map(o => ({...o}));
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.