Spread with map vs Array.from with map vs Array.from with second parameter vs for loop push vs for loop pre-allocate vs for loop pre-allocate cached lengthFastest: for loop pre-allocate cached length (3.4x faster)
263,019 ops/sec
209,618 ops/sec
184,689 ops/sec
83,830 ops/sec
80,834 ops/sec
78,247 ops/sec
Results show median performance across all community submissions. Run this benchmark yourself to verify on your device.
| Test case name | Result |
|---|---|
| Spread with map | |
| Array.from with map | |
| Array.from with second parameter | |
| for loop push | |
| for loop pre-allocate | |
| for loop pre-allocate cached length |
| Test name | Executions per second |
|---|---|
| ✓ for loop pre-allocate cached length | 551,054 Ops/sec |
| Array.from with second parameter | 407,040 Ops/sec |
| Spread with map | 404,565 Ops/sec |
| for loop pre-allocate | 383,677 Ops/sec |
| Array.from with map | 383,415 Ops/sec |
| for loop push | 367,298 Ops/sec |