prototype or static function

JavaScript performance comparison

Test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    function Obj()
    {
    this.a = 1;
    this.b = 2;
    }
   
    Obj.prototype.testL = function()
    {
    return this.a + this.b;
    }
   
    Obj.prototype.testLG = function()
    {
    testG(this.a, this.b)
    }
   
    Obj.prototype.testLL = function()
    {
    this.testLLa(this.a, this.b);
    }
   
    Obj.prototype.testLLa = function(a, b)
    {
    return a + b;
    }
   
    Obj.prototype.testLLo = function()
    {
    testLO(this);
    }
   
   
    function testG(a, b)
    {
    return a + b;
    }
   
    function testLO(obj)
    {
    return obj.a + obj.b;
    }
   
    var obj = new Obj();
};
</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
local
obj.testL();
pending…
global
testG(obj.a, obj.b);
pending…
global in local
obj.testLG();
pending…
local in local
obj.testLL();
pending…
pass an obj
testLO(obj);
pending…
pass an obj local
obj.testLLo();
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