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:
6 months ago
Array.prototype.slice
6.1M/s
Array.prototype.concat
6.0M/s
Spread Syntax
5.9M/s
Array.from
5.8M/s
For Loop Assign
807K/s
For Loop Push
279K/s
View exact numbers
Test name
Executions per second
✓
Array.prototype.slice
6,050,452 Ops/sec
Array.prototype.concat
5,959,004 Ops/sec
Spread Syntax
5,944,368 Ops/sec
Array.from
5,806,137 Ops/sec
For Loop Assign
806,800 Ops/sec
For Loop Push
278,883 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];