Dynamic versus fixed array

JavaScript performance comparison

Test case created by Joshua

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  dataDynamic = [];
  for (var i = 0, position = 0, length = 100; i < length; i++) {
    var number = Math.floor(Math.random() * 1000);
    dataDynamic[position] = {
      id: 'item' + i,
      last: number + 1000,
      next: number
    };
    position++;
  }
  
  dataFixed = new Array(100);
  for (var i = 0, position = 0, length = 100; i < length; i++) {
    var number = Math.floor(Math.random() * 1000);
    dataFixed[position] = {
      id: 'item' + i,
      last: number + 1000,
      next: number
    };
    position++;
  }

};
</script>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Dynamic Array
for (var i = 0, length = 100; i < length; i++) {
  console.log(dataDynamic[i])
}
pending…
Fixed Array
for (var i = 0, length = 100; i < length; i++) {
  console.log(dataFixed[i])
}
pending…

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

Compare results of other browsers

0 Comments