array of objects vs array of numbers

JavaScript performance comparison

Test case created by Timo

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var point = function(x,y)
    {
     this.X=x;
     this.Y=y;
    }
    var point_array=[new point(10,20),new point(10,20),new point(10,20),new point(10,20),new point(10,20),new point(10,20),new point(10,20),new point(10,20),new point(10,20),new point(10,20)];
    var x_array=[10,10,10,10,10,10,10,10,10,10];
    var y_array=[20,20,20,20,20,20,20,20,20,20];
    var len = x_array.length;
    var temp=0;
};
</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Reading point array
for(var i = 0; i<len;i++)
{
  temp+=point_array[i].X+point_array[i].Y;
}
pending…
Reading xy array
for(var i = 0; i<len;i++)
{
  temp += x_array[i] + y_array[i];
}
pending…
Reading point array using temp
for(var i = 0; i<len;i++)
{
  temp2=point_array[i];
  temp+=temp2.X + temp2.Y;
}
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. Here’s a list of current revisions for this page:

0 comments

Add a comment