Prototype vs. this (v39)

Revision 39 of this benchmark created by Brendan Ashworth on


Setup

function T() {
    }
    
    T.prototype.myDefault1 = null;
    T.prototype.myDefault2 = [1, 2, 3];
    T.prototype.myDefault3 = {something: 'else'};
    
    function Tt() {
      this.myDefault1 = null;
      this.myDefault2 = [1, 2, 3];
      this.myDefault3 = {something: 'else'};
    }

Test runner

Ready to run.

Testing in
TestOps/sec
Using prototype
for (var i = 1; i <= 20000; i++) {
  var x = new T();
  x.myDefault1;
  x.myDefault2;
  x.myDefault3;
}
ready
Using this
for (var i = 1; i <= 20000; i++) {
  var x = new Tt();
  x.myDefault1;
  x.myDefault2;
  x.myDefault3;
}
ready

Revisions

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