Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
[] + push vs new Array() + index insertion (random insertion order) (fixed)
(version: 1)
Comparing performance of:
[] + push vs new Array() + index insertion
Created:
one year ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
const ITEMS_COUNT = 100000 function shuffleArray(array) { for (var i = array.length - 1; i >= 0; i--) { var j = Math.floor(Math.random() * (i + 1)); var temp = array[i]; array[i] = array[j]; array[j] = temp; } return array; } const ITEMS_IN_RANDOM_ORDER = shuffleArray(Array.from(Array(ITEMS_COUNT).keys()))
Tests:
[] + push
const arr = []; for (const i of ITEMS_IN_RANDOM_ORDER) { arr.push(i); }
new Array() + index insertion
const arr = new Array(ITEMS_COUNT) for (const i of ITEMS_IN_RANDOM_ORDER) { arr[i] = i }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
[] + push
new Array() + index insertion
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
3 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:146.0) Gecko/20100101 Firefox/146.0
Browser/OS:
Firefox 146 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
[] + push
598.1 Ops/sec
new Array() + index insertion
91.7 Ops/sec
Related benchmarks:
javascript loops
loopings
Array Entries vs fori
at vs index
Array append: Array spread vs. for loop
javascript loops small
javascript loops with reduce 4
javascript loops v2
[] + push vs new Array() + index insertion (random insertion order)
Comments
Confirm delete:
Do you really want to delete benchmark?