Class properties via constructor this or via prototype

JavaScript performance comparison

Test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  function ctorProps (a,b,c,d,e,f,g) {
  this.a=a;
  this.b=b;
  this.c=c;
  this.d=d;
  this.e=e;
  this.f=f;
  this.g=g;
  }
  
  ctorProps.prototype.method = function (a,b,c,d,e,f,g) {
  this.a+=a;
  this.b+=b;
  this.c+=c;
  this.d+=d;
  this.e+=e;
  this.f+=f;
  this.g+=g;
  };
  
  function protoProps (a,b,c,d,e,f,g) {
  this.a=a;
  this.b=b;
  this.c=c;
  this.d=d;
  this.e=e;
  this.f=f;
  this.g=g;
  }
  
  protoProps.prototype.a = 0;
  protoProps.prototype.b = 0;
  protoProps.prototype.c = 0;
  protoProps.prototype.d = 0;
  protoProps.prototype.e = 0;
  protoProps.prototype.f = 0;
  protoProps.prototype.g = 0;
  
  protoProps.prototype.method = function (a,b,c,d,e,f,g) {
  this.a+=a;
  this.b+=b;
  this.c+=c;
  this.d+=d;
  this.e+=e;
  this.f+=f;
  this.g+=g;
  };
  
  var instance;

};
</script>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
ctorProps
instance = new ctorProps(1,2,3,4,5,6,7);
pending…
protoProps
instance = new protoProps(1,2,3,4,5,6,7);
pending…

Compare results of other browsers

Revisions

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

0 Comments