Raw Object vs Raw Array Vector

JavaScript performance comparison

Test case created by Greggman

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var ov1 = { x: 1, y: 2, z: 3 };
    var ov2 = { x: 3, y: 4, z: 5 };
   
    var av1 = [1, 2, 3];
    var av2 = [3, 4, 5];
   
    function addOb(a, b) {
      a.x += b.x;
      a.y += b.y;
      a.z += b.z;
    };
   
    function addAr(a, b) {
      a[0] += b[0];
      a[1] += b[1];
      a[2] += b[2];
    };
   
   
};
</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
As Object
addOb(ov1, ov2);
pending…
As Array
addAr(av1, av2);
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:

1 comment

trigrou commented :

Seriously objects faster than arrays ... It does not make sense :)

Add a comment