push allocated vs dynamic (v30)

Revision 30 of this benchmark created by Fabio Costa on


Description

is it usefull to pre-allocate the array by setting the last value first when assigning some values ?

Setup

var n = 30;

Test runner

Ready to run.

Testing in
TestOps/sec
push
var myArray = [];
for (var i=0; i<n; i++) { myArray.push(i); }
ready
push/allocated
var myArray = new Array(n);
for (var i=0; i<n; i++) { myArray.push(i); }
ready
set
var myArray = [];
for (var i=0; i<n; i++) { myArray[i] = i; }
ready
set/allocated
var myArray = new Array(n);
for (var i=0; i<n; i++) { myArray[i] = i; }
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.