var vertices = [
[1, 0, 0, 0],
[0, 1, 0, 0],
[0, 0, 1, 0],
[0, 0, 0, 1],
]
var myCopy = null;
myCopy = JSON.parse(JSON.stringify(vertices));
myCopy = vertices.slice();
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
JSON.stringify | |
structuredClone |
Test name | Executions per second |
---|---|
JSON.stringify | 951558.0 Ops/sec |
structuredClone | 9043959.0 Ops/sec |
Let's break down the provided JSON and explain what's being tested.
Benchmark Definition
The benchmark is testing two approaches to create a copy of an array: JSON.stringify
and slice()
(also known as structuredClone
in modern JavaScript).
Options Compared
Pros and Cons
Library and Purpose
In this benchmark, structuredClone
is used as a way to compare the performance of slice()
with JSON.stringify
. However, it's worth noting that structuredClone
is a relatively new feature in JavaScript (introduced in ECMAScript 2022) and may not be supported in older browsers or environments.
Special JS Feature/Syntax
There are no special JS features or syntax used in this benchmark. The code is standard JavaScript and does not rely on any experimental or proprietary features.
Other Alternatives
If you're interested in exploring alternative approaches, here are a few options:
Array.from()
and then creating a new array by mapping over the original array.These alternatives may have different performance characteristics and trade-offs compared to the options tested in this benchmark.