`Array.slice(0, N)` vs `Array.length = N`
4 months ago
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36
Test name |
Executions per second |
`Array.slice(0, N)` |
14201890.0 Ops/sec |
`Array.length = N` |
10926810.0 Ops/sec |
`Object.assign([], arr)` with `Array.length = N` |
283612.8 Ops/sec |
Tests:
-
`Array.slice(0, N)`
-
`Array.length = N`
-
`Object.assign([], arr)` with `Array.length = N`
Open this result on MeasureThat.net