Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0
Chrome 131
Mac OS X 10.15.7
Desktop
one year ago
Benchmark.js
`Array.slice(0, N)`
58.2M/s
`Array.length = N`
50.1M/s
`Object.assign([], arr)` with `Array.length = N`
884K/s
View exact numbers
Test name Executions per second
`Array.slice(0, N)` 58,170,336 Ops/sec
`Array.length = N` 50,082,004 Ops/sec
`Object.assign([], arr)` with `Array.length = N` 883,758 Ops/sec
Script Preparation code:
Tests: