Prototype vs. this (v56)

Revision 56 of this benchmark created on


Setup

var T = function() {};
    
    T.prototype.myMethod = function(i) {
      if (i == 20000) {
        console.log('Hey T!');
      }
    };
    
    var Tt = function() {
      var myMethod = function(i) {
        if (i == 20000) {
          console.log('Hey Tt!');
        }
      };
      return {
        myMethod: myMethod
      };
    }();

Test runner

Ready to run.

Testing in
TestOps/sec
Using prototype
var x = new T();
for (var i = 1; i <= 20000; i++) {

  x.myMethod(i);
}
ready
Using this
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.