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/149.0.0.0 Safari/537.36
Browser:
Chrome 149
Operating system:
Windows
Device Platform:
Desktop
Date tested:
22 days ago
Spread Syntax
5.4M/s
Array.prototype.slice
4.2M/s
Array.prototype.concat
3.3M/s
Array.from
2.5M/s
For Loop Assign
413K/s
For Loop Push
62K/s
View exact numbers
Test name
Executions per second
✓
Spread Syntax
5,417,269 Ops/sec
Array.prototype.slice
4,214,846 Ops/sec
Array.prototype.concat
3,265,912 Ops/sec
Array.from
2,545,347 Ops/sec
For Loop Assign
412,600 Ops/sec
For Loop Push
61,830 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];