Prototype vs. this (v51)

Revision 51 of this benchmark created on


Description

Moving the object instantiation outside prep block.

Setup

function T() {
      this.name = 'T';
    }
    
    T.prototype.myMethod = function(i) {
      if (i == 20000) {
        console.log('Hey ' + this.name);
      }
    };
    
    function Tt() {
      this.name = 'Tt';
      this.myMethod = function(i) {
        if (i == 20000) {
          console.log('Hey ' + this.name);
        }
      };
    }

Test runner

Ready to run.

Testing in
TestOps/sec
Using prototype
 var t = new T();
 for (var i = 1; i <= 20000; i++) {
   t.myMethod(i);
 }
ready
Using this
var tt = new Tt();
for (var i = 1; i <= 20000; i++) {
  tt.myMethod(i);
}
ready

Revisions

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