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.concat
8.7M/s
Array.prototype.slice
8.5M/s
Spread Syntax
8.3M/s
Array.from
6.9M/s
For Loop Assign
836K/s
For Loop Push
281K/s
View exact numbers
Test name
Executions per second
✓
Array.prototype.concat
8,715,834 Ops/sec
Array.prototype.slice
8,545,428 Ops/sec
Spread Syntax
8,315,384 Ops/sec
Array.from
6,909,453 Ops/sec
For Loop Assign
836,364 Ops/sec
For Loop Push
280,800 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];