push allocated vs dynamic

JavaScript performance comparison

Revision 17 of this test case created by tetra

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=10000;
    var myArray = [];
   
    var typedArray = new Int32Array(10000);
};
</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
for (var i=0; i<n; i++) { myArray.push(i) }
pending…
reverse writing
  var i=n;
  while (i--) { myArray[i] =i }  
pending…
reverse writing, array allocated with Array constructor
  var i=n;
  while (i--) { myArray[i] =i }  
pending…
typed array rev
for(i=n-1; i>=0; i--){
typedArray[i] =i
}
pending…
typed array
for(i=0; i<n; i++){
   typedArray[i] =i
}
 
pending…
for with direct write
for (var i=0; i<=n; i++) { myArray[i] = i }
pending…
for with direct write rev
for (var i=n; i>=0; i--) { myArray[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