Closure vs. property
JavaScript performance comparison
Preparation code
<script>
Benchmark.prototype.setup = function() {
function ClosureColor(name) {
Object.defineProperties(this, {
// Have no choice but to add these methods to the instance
name: {
get: function () {
return name;
},
set: function (n) {
name = n;
}
}
});
}
function PropertyColor(name) {
this._name = name;
Object.defineProperties(this, {
name: {
get: function () {
return this._name;
},
set: function (n) {
this._name = n;
}
}
});
}
function PrototypeColor(name) {
this._name = name;
}
PrototypeColor.prototype = {
get name() {
return this._name;
},
set name(name) {
this._name = name;
}
};
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
Test | Ops/sec | |
---|---|---|
Closure
|
|
pending… |
Property
|
|
pending… |
Prototype
|
|
pending… |
Compare results of other browsers
Revisions
You can edit these tests or add even more tests to this page by appending /edit
to the URL.
- Revision 1: published Axel Rauschmayer
- Revision 2: published Andrea Giammarchi
- Revision 3: published
- Revision 4: published Axel Rauschmayer
- Revision 5: published
- Revision 6: published
- Revision 7: published Jacob Chapel
- Revision 8: published sorensen
- Revision 9: published Jacob Chapel
- Revision 10: published Paul Masurel
- Revision 11: published noah
- Revision 12: published
- Revision 13: published
- Revision 14: published Benoit Marchant
- Revision 15: published
- Revision 16: published Frederik Krautwald
- Revision 17: published Frederik Krautwald
- Revision 19: published mucaho
- Revision 20: published mucaho
- Revision 25: published Nicolas RAIBAUD
- Revision 26: published Nicolas RAIBAUD
0 Comments