Instantiation speed using prototyped non-function properties.

JavaScript performance comparison

Test case created

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.

Testing in unknown unknown
Test Ops/sec
Without prototyped properties
var p = new NormalThing( 'Craig' );
pending…
With prototyped properties, undefined values
var p = new ProtoThing1( 'Craig' );
pending…
With prototyped properties, defined values
var p = new ProtoThing2( 'Craig' );
pending…

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers

0 comments

Add a comment