prototype or static function
JavaScript performance comparison
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.
| Test | Ops/sec | |
|---|---|---|
local |
|
pending… |
global |
|
pending… |
global in local |
|
pending… |
local in local |
|
pending… |
pass an obj |
|
pending… |
pass an obj local |
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit to the URL.
0 comments