DefineProperty vs regular property
JavaScript performance comparison
Preparation code
<script>
Benchmark.prototype.setup = function() {
var definedProperty = function () {
Object.defineProperty(this, "prop", {
configurable: true,
enumerable: true,
writable: true,
value: 4
});
}
var definedConstantProperty = function () {
Object.defineProperty(this, "prop", {
configurable: true,
enumerable: true,
writable: false,
value: 4
});
}
var regularProperty = function () {
this.prop = 4;
}
var count = 500;
var defineds = new Array(count);
var definedConsts = new Array(count);
var regulars = new Array(count);
for (var i = 0; i < count; i++) {
defineds[i] = new definedProperty();
definedConsts[i] = new definedConstantProperty();
regulars[i] = new regularProperty();
}
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
defineProperty |
|
pending… |
regular property |
|
pending… |
defineProperty with writable=false |
|
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. Here’s a list of current revisions for this page:
- Revision 1: published by Kevin Gadd
- Revision 3: published
- Revision 4: published
0 comments