Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36
Chrome 130
Mac OS X 10.15.7
Desktop
one year ago
Benchmark.js
`Array.slice(0, N)`
43.2M/s
`Array.length = N`
36.3M/s
`Object.assign([], arr)` with `Array.length = N`
663K/s
View exact numbers
Test name Executions per second
`Array.slice(0, N)` 43,217,708 Ops/sec
`Array.length = N` 36,252,636 Ops/sec
`Object.assign([], arr)` with `Array.length = N` 662,873 Ops/sec
Script Preparation code:
Tests: