Three.js - Vertex / Vector3

JavaScript performance comparison

Revision 2 of this test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var Vector3, Vertex, j;
    Vector3 = function(x, y, z) {
      this.x = x;
      this.y = y;
      this.z = z;
    };
    Vector3.prototype = {
      constructor: Vector3,
      addScalar: function(scalar) {
        this.x += scalar;
        this.y += scalar;
        this.z += scalar;
      }
    }
   
    Vertex = function() {
      Vector3.apply(this, arguments)
    };
    Vertex.prototype = new Vector3;
    Vertex.prototype.constructor = Vertex;
   
    VertexB = function() {
      Vertex.apply(this, arguments)
    };
    VertexB.prototype = new Vertex;
    VertexB.prototype.constructor = VertexB;
   
    VertexC = function() {};
    VertexC.prototype = new Vector3;
    VertexC.prototype.constructor = VertexC;
   
    VertexD = function(x, y, z) {
      Vector3.call( this );
      this.x = x;
      this.y = y;
      this.z = z;
    };
    VertexD.prototype = new Vector3();
    VertexD.prototype.constructor = VertexD;
   
    OldVertex = function() {
        this.position = new Vector3();
    };
};
</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
vector3
j = new Vector3(0, 0, 0);
j.addScalar(1);
pending…
vertex
j = new Vertex(0, 0, 0);
j.addScalar(1);
pending…
VertexB
j = new VertexB(0, 0, 0);
j.addScalar(1);
pending…
VertexC
j = new VertexC(0, 0, 0);
j.addScalar(1);
pending…
VertexD
j = new VertexD(0, 0, 0);
j.addScalar(1);
pending…
Assign vector3 to object
j = new Object();
j.p = new Vector3(0, 0, 0);
j.p.addScalar(1);
pending…
OldVertex
j = new OldVertex();
j.position.addScalar(1);
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

Renato Nitta commented :

Hello there,

Nice tests!

I'm curious about the performance of the same browser, but on different OS, like: "chrome on ubuntu", "chrome on osx", "chrome on windows".

Do you have plans to show this kind of info?

Add a comment