push allocated vs dynamic

JavaScript performance comparison

Revision 13 of this test case created

Info

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

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var n=1000;
    var myArray = [];
    var myArray1 = new Array(n+1);
    var myArray2 = new Array();
    var myArray3 = new Array(n/2);
    var myArray4 = new Array();
    var myArray5 = [];
   
};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
push
  var i=0;
  while (i<n) { myArray[i] =i; i++ }  
pending…
reverse writing
  var i=0;
  while (i<n) { myArray1[i] =i; i++ }  
pending…
reverse writing, array allocated with Array constructor
  var i=0;
  while (i<n) { myArray2[i] =i; i++ }  
pending…
  var i=0;
  while (i<n) { myArray3[i] =i; i++ }  
pending…
  var i=0;
  while (i<n) { myArray4.push(i); i++ }  
pending…
  var i=0;
  while (i<n) { myArray5.push(i); i++ }  
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment