Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
JavaScript Array Shallow Copy: Array.from vs Spread Syntax vs Array.prototype.slice vs Array.prototype.concat
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36
Browser:
Chrome 144
Operating system:
Windows
Device Platform:
Desktop
Date tested:
3 months ago
Test name
Executions per second
Array.from
6909453.0 Ops/sec
Spread Syntax
8315384.5 Ops/sec
Array.prototype.slice
8545428.0 Ops/sec
Array.prototype.concat
8715834.0 Ops/sec
For Loop Push
280799.5 Ops/sec
For Loop Assign
836364.1 Ops/sec
Script Preparation code:
const array = []; for (let i = 0; i < 1024; i++) array.push(i);
Tests:
Array.from
const a = Array.from(array);
Spread Syntax
const a = [...array];
Array.prototype.slice
const a = array.slice();
Array.prototype.concat
const a = array.concat();
For Loop Push
const a = []; for (const i of array) a.push[i];
For Loop Assign
const a = new Array(array.length); for (let i = 0; i < a.length; i++) a[i] = array[i];