Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36
Chrome 121
Windows
Desktop
2 years ago
Benchmark.js
`Array.slice(0, N)`
10.5M/s
`Array.length = N`
9.7M/s
`Object.assign([], arr)` with `Array.length = N`
247K/s
View exact numbers
Test name Executions per second
`Array.slice(0, N)` 10,483,912 Ops/sec
`Array.length = N` 9,652,563 Ops/sec
`Object.assign([], arr)` with `Array.length = N` 247,184 Ops/sec
Script Preparation code:
Tests: