Testing browser speed in appending 500.000 zeros to an array, please wait...

 

Code of the simple script used to do this test

var arr1 = [], arr2 = [], start_time, end_time, duration_of_length, duration_of_push;
         
start_time = new Date().getTime();
for(var i = 0; i < 500000; ++i)
   arr1[arr1.length] = 0;
end_time = new Date().getTime();
duration_of_length = ((end_time - start_time) / 1000);

start_time = new Date().getTime();
for(var i = 0; i < 500000; ++i)
   arr2.push(0);
end_time = new Date().getTime();
duration_of_push = ((end_time - start_time) / 1000);

document.getElementById('results').innerHTML = "Appending 500.000 zeros into an array
using length: " + duration_of_length + "
using push: " + duration_of_push;