Konstruct
JavaScript performance comparison
Info
Test direct args vs Konstructor nonsense
Preparation code
<script>
Benchmark.prototype.setup = function() {
var kPooler = function() {
var Klass = this;
if (Klass.instancePool.length) {
var instance = Klass.instancePool.pop();
Klass.call(instance, arguments);
return instance;
}
if (!Klass.construct) {
function Konstructor(args) {
return Klass.apply(this, args);
}
Konstructor.prototype = Klass.prototype;
Klass.construct = function(args) {
return new Konstructor(args);
}
}
return Klass.construct(arguments);
};
var fiveArgumentPooler = function(a1, a2, a3, a4, a5) {
var Klass = this;
if (Klass.instancePool.length) {
var instance = Klass.instancePool.pop();
Klass.call(instance, a1, a2, a3, a4, a5);
return instance;
} else {
return new Klass(a1, a2, a3, a4, a5);
}
}
function Foo(a,b,c,d,e) {
this.a = a;
this.b = b;
this.c = c;
this.d = d;
this.e = e;
}
Foo.kp = kPooler;
Foo.fp = fiveArgumentPooler;
Foo.instancePool = []; // not really used - here other than checking length
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
direct |
|
pending… |
konstruct! |
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit to the URL.
0 comments