test prototype

JavaScript performance comparison

Test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    function ClassA(a, b, c, d)
    {
        this._a = a;
        this._b = b;
        this._c = c;
        this._d = d;
    }
   
    ClassA.prototype =
    {
        selfAccess : function()
        {
                this._a = this._b + this._c + this._d;
                this._b = this._b + this._c + this._d;
                return this._a + this._b + this._c + this._d;
        }
   
    }
   
    function ClassPlatform()
    {
        this._classA = new ClassA(1,2,3,4);
   
    }
   
    ClassPlatform.prototype =
    {
        varPass : function(a, b, c, d)
        {
                a = b + c + d;
                b = b + c + d;
                return a + b + c + d;
        },
   
        objPass : function(obj)
        {
                obj._a = obj._b + obj._c + obj._d;
                obj._b = obj._b + obj._c + obj._d;
                return obj._a + obj._b + obj._c + obj._d;
        },
   
        callLocal : function()
        {
                this._classA.selfAccess();
        },
   
        callObjPass : function()
        {
                this.objPass(this._classA);
        },
   
        callVarPass : function()
        {
                this.varPass(this._classA._a, this._classA._b, this._classA._c, this._classA._d);
        }
    }
   
    var cp = new ClassPlatform();
    var cA = new ClassA(1,2,3,4);
};
</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
callLocal
cp.callLocal();
 
pending…
callObjPass
cp.callObjPass();
pending…
call local outside
cA.selfAccess()
pending…
callObjPass outside
cp.objPass(cA);
pending…
callVarPass
cp.callVarPass();
pending…

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

Compare results of other browsers

0 comments

Add a comment