Push item to an array vs Append an item by spread vs Direct assign an item to an initialized array vs items[items.length] vs items[items.length] outer length counter vs items[items.length] outer length counter + new Array() vs Cutting empty tailFastest: Direct assign an item to an initialized array (179.8x faster)
112,368 ops/sec
109,864 ops/sec
75,746 ops/sec
72,292 ops/sec
50,079 ops/sec
625 ops/sec
Results show median performance across all community submissions. Run this benchmark yourself to verify on your device.
| Test case name | Result |
|---|---|
| Push item to an array | |
| Append an item by spread | |
| Direct assign an item to an initialized array | |
| items[items.length] | |
| items[items.length] outer length counter | |
| items[items.length] outer length counter + new Array() | |
| Cutting empty tail |
| Test name | Executions per second |
|---|---|
| ✓ Direct assign an item to an initialized array | 74,115 Ops/sec |
| items[items.length] outer length counter + new Array() | 71,488 Ops/sec |
| Cutting empty tail | 64,241 Ops/sec |
| items[items.length] | 44,867 Ops/sec |
| items[items.length] outer length counter | 44,741 Ops/sec |
| Push item to an array | 36,145 Ops/sec |
| Append an item by spread | 66 Ops/sec |