with or without optional arguments

Benchmark created by gero3 on


Setup

var Vector3 = function(x,y,z){
    
        this.x = x;
        this.y = y;
        this.z = z;
    
    };
    
    Vector3.add = function(a,b){
    
        a.x = a.x + b.x;
        a.y = a.y + b.y;
        a.z = a.z + b.z;
    
    }
    
    Vector3.prototype.add = function(b){
    
        this.x += b.x;
        this.y += b.y;
        this.z += b.z;
    
    };
    
    Vector3.prototype.addMultiple = function(b,c,d,e){
    
    
        this.x += b.x;
        this.y += b.y;
        this.z += b.z;
    
        if (c) {
    
            this.x += c.x;
            this.y += c.y;
            this.z += c.z;
    
        }
    
        if (d) {
    
            this.x += d.x;
            this.y += d.y;
            this.z += d.z;
    
        }
    
        if (e) {
    
            this.x += e.x;
            this.y += e.y;
            this.z += e.z;
    
        }
    
    };
    
    
    Vector3.prototype.chainedadd = function(b){
    
        this.x += b.x;
        this.y += b.y;
        this.z += b.z;
    
        return this;
    
    };
    
    var a = new Vector3(0.1,0.2,0.4);
    var b = new Vector3(1.98714,-0.2,0.5787789);
    var c = new Vector3(-2.45478756325,0.2,-0.78254656);
    var d = new Vector3(-1.98714,0.2,-0.5787789);
    var e = new Vector3(2.45478756325,-0.2,0.78254656);

Test runner

Ready to run.

Testing in
TestOps/sec
without optional arguments
a.add(b);
a.add(c);
a.add(d);
a.add(e);
ready
with optional arguments1
a.addMultiple(b,c,d,e);
 
ready
with optional arguments2
a.addMultiple(b);
a.addMultiple(c);
a.addMultiple(d);
a.addMultiple(e);
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.

  • Revision 1: published by gero3 on