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

Revision 132 of this benchmark created on


Description

I have an application which stores coordinates and performs calculation on them. I wanted to know if a matrix or an object would be a better choice.

My experience: every f***ing browser have a different result. firefox : the 2. one is the fastest ie : the 4. is the fastest but only with a little chrome : the 4. is twice as fast as any other...

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, 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.