Object creation speed --- method on object vs. on prototype

Benchmark created by Asheq on


Setup

function A() {}
  
  A.prototype.myMethod = function(i) {
    console.log('Hey A!');
  };
  
  function B() {
    this.myMethod = function(i) {
      console.log('Hey B!');
    };
  }

Test runner

Ready to run.

Testing in
TestOps/sec
Method on prototype
var a = new A();
ready
Method on object
var b = new B();
ready

Revisions

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

  • Revision 1: published by Asheq on