Property type vs Instantiation speed

JavaScript performance comparison

Test case created


Will objects instantiate faster if all properties are prototyped, even if the constructor must overwrite all properties?

Preparation code

  function NormalThing(name) { = name;

  function ProtoThing1(name) { = name;
  } = undefined;

  function ProtoThing2(name) { = 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');
With prototyped properties, undefined values
var p = new ProtoThing1('Craig');
With prototyped properties, values defined.
var p = new ProtoThing2('Craig');

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

Compare results of other browsers


Comment form temporarily disabled.

Add a comment