Performance of Nested Arrays vs. Array of objects within objects (v140)

Revision 140 of this benchmark created on


Setup

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, i, y){
             arr[i][y] = Math.sin(rad(degree));
          },
      };
      
      function rad(degree){
         return Math.PI*degree/180;
      };

Test runner

Ready to run.

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

Revisions

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