Property type vs Instantiation speed
JavaScript performance comparison
Info
Will objects instantiate faster if all properties are prototyped, even if the constructor must overwrite all properties?
Preparation code
<script>
function NormalThing(name) {
this.name = name;
}
function ProtoThing1(name) {
this.name = name;
}
ProtoThing1.prototype.name = undefined;
function ProtoThing2(name) {
this.name = name;
}
ProtoThing2.prototype.name = "string"
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Without prototyped properties |
|
pending… |
With prototyped properties, undefined values |
|
pending… |
With prototyped properties, values defined. |
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit to the URL.
0 comments