Instantiation speed using prototyped non-function properties.
JavaScript performance comparison
Info
Will objects instantiate faster if all properties are prototyped, even if the constructor must overwrite all properties?
Preparation code
function NormalThing( name ) {
this.name = name;
}
function ProtoThing1( name ) {
this.name = name;
}
ProtoThing.prototype.name = undefined;
function ProtoThing2( name ) {
this.name = name;
}
ProtoThing.prototype.name = "string"
Preparation code output
function NormalThing( name ) {
this.name = name;
}
function ProtoThing1( name ) {
this.name = name;
}
ProtoThing.prototype.name = undefined;
function ProtoThing2( name ) {
this.name = name;
}
ProtoThing.prototype.name = "string"
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, defined values |
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit to the URL.
0 comments