Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Add item to array: push vs spread vs assign vs assign+grow
(version: 0)
Comparing performance of:
Push item to an array vs Append an item by spread vs Direct assign an item to an initialized array vs Direct assign an item to an empty array
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
window.MAX_SIZE = 1000;
Tests:
Push item to an array
const items = []; for (let i = 0; i < MAX_SIZE; i++) { items.push(i); }
Append an item by spread
let items = []; for (let i = 0; i < MAX_SIZE; i++) { items = [...items, i]; }
Direct assign an item to an initialized array
const items = new Array(MAX_SIZE); for (let i = 0; i < MAX_SIZE; i++) { items[i] = i; }
Direct assign an item to an empty array
const items = new Array(); for (let i = 0; i < MAX_SIZE; i++) { items[i] = i; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Push item to an array
Append an item by spread
Direct assign an item to an initialized array
Direct assign an item to an empty array
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Related benchmarks:
Add item to array: push vs spread vs assign:
spread vs push large
In loop, push(...) vs spread v2
Add item to array: push vs spread vs assign vs assign with from:
Comments
Confirm delete:
Do you really want to delete benchmark?