Raw Object vs Raw Array Vector

JavaScript performance comparison

Revision 2 of this test case created by trigrou

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var ov1 = { x: 1.0, y: 2.0, z: 3.0 };
    var ov2 = { x: 3.0, y: 4.0, z: 5.0 };
   
    var av1 = [1.0, 2.0, 3.0];
    var av2 = [3.0, 4.0, 5.0];
   
    var ta1 = new Float32Array(av1);
    var ta2 = new Float32Array(av2);
   
    var tta1 = new Float64Array(av1);
    var tta2 = new Float64Array(av2);
       
    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];
    };
   
    function addTA(a, b) {
     a[0] += b[0];
     a[1] += b[1];
     a[2] += b[2];
    };
   
    function addTA2(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 TypedArray 32
addTA(ta1, ta2 );
pending…
As Array
addAr(av1, av2);
pending…
As Object
addOb(ov1, ov2);
pending…
As TypedArray 64
addTA2(tta1, tta2 );
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