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

Revision 131 of this benchmark created on


Setup

var arr = [],
          point = function(y){ this.x = y; },
          obj = { array : [] };
      
      for(var i = 0; i < 100; 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;
      };

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