Performance of Nested Arrays vs. Array of objects within objects

JavaScript performance comparison

Revision 132 of this test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
      var arr = [],
          point = function(y){ this.x = y; },
          obj = { array : [] };
      
      for(var i = 0; i < 10000; i++) {
          obj.array.push(new point(i));
          var nested_arr = [1];
          arr.push(nested_arr);
      };
      
      var process = {
          object_sin : function(degree, point){
             point.x = Math.sin(rad(degree));
          },
          array_sin : function(degree, point){
             return Math.sin(rad(degree));
          },
      };
      
      function rad(degree){
         return Math.PI*degree/180;
      };

};
</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
Nested Array Performance
for(var i = 0; i < arr.length; i++){
    for(var y = 0; y < arr[i].length; y++){
        arr[i][y] = process.array_sin(30);
    }
}
pending…
Nested Array Performance
var i = 0,
    len = arr.length;
for( i = 0; i < len; i++){
    var y = 0,
    leng = arr[i].length;
    for( y = 0; y < leng; y++){
        arr[i][y] = process.array_sin(30);
    }
}
pending…
Nested Array Performance
for(var i = 0; i < arr.length; ++i){
    for(var y = 0; y < arr[i].length; ++y){
       arr[i][y] = process.array_sin(30);
    }
}
pending…
Object with array property storing objects performance
var x = obj.array.length;
while(--x){
process.object_sin(30, obj.array[x]);
}
pending…
Object with array property storing objects performance
var x = 0;
while(++x < obj.array.length){
process.object_sin(30, obj.array[x]);
}
pending…
Object with array property storing objects performance
for(var i = 0; i < obj.array.length; i++){
process.object_sin(30, obj.array[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.

0 Comments