Contructor public properties (no functions)

JavaScript performance comparison

Test case created by Toni

Info

Compare performance on public properties using constructor or prototypes.

Preparation code

<script>
  function ConstructorPublicProperties() {
    this.publicProperty1 = 1;
    this.publicProperty2 = 2;
    this.publicProperty3 = 3;
    this.publicProperty4 = 4;
    this.publicProperty5 = 5;
    this.publicProperty6 = 6;
    this.publicProperty7 = 7;
    this.publicProperty8 = 8;
    this.publicProperty9 = 9;
  }

  function PrototypePublicProperties() {}

  PrototypePublicProperties.prototype = {
    publicProperty1: 1,
    publicProperty2: 2,
    publicProperty3: 3,
    publicProperty4: 4,
    publicProperty5: 5,
    publicProperty6: 6,
    publicProperty7: 7,
    publicProperty8: 8,
    publicProperty9: 9
  };
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
instanciate constructor public properties
for (var i = 0; i < 1000; i++) {
  new ConstructorPublicProperties();
}
pending…
instanciate prototype public properties
for (var i = 0; i < 1000; i++) {
  new PrototypePublicProperties();
}
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