push allocated vs dynamic (v18)

Revision 18 of this benchmark created on


Description

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

Setup

var n=10000;
    var myArray1 = [];
    var myArray2 = new Array(10000);
    
    var typedArray = new Int32Array(10000);

Test runner

Ready to run.

Testing in
TestOps/sec
push
for (var i=0; i<n; i++) { myArray1.push(i) }
ready
reverse writing
  var i=n;
  while (i--) { myArray1[i] =i }  
ready
reverse writing, array allocated with Array constructor
  var i=n;
  while (i--) { myArray2[i] =i }  
ready
for loop, array allocated with Array constructor
  var i=n;
  for(var i =0;i<n;i++) { myArray2[i] =i }  
 
ready
typed array rev

for(i=n-1; i>=0; i--){
typedArray[i] =i
}
ready
typed array
for(i=0; i<n; i++){
   typedArray[i] =i
}
ready
for with direct write
for (var i=0; i<=n; i++) { myArray1[i] = i }
ready
for with direct write rev
for (var i=n; i>=0; i--) { myArray1[i] = i }
ready

Revisions

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