Constructer vs Function

Benchmark created by Daiwei on


Setup

function MyClass(a) {
      this.a = a;
    }
    
    MyClass.prototype.calc = function () {
      return this.a + this.a;
    };
    
    function myFunction(a) {
      return a + a;
    }

Test runner

Ready to run.

Testing in
TestOps/sec
Constructor
var myInstance = new MyClass(2);
myInstance.calc();
ready
Function
myFunction(2);
ready

Revisions

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

  • Revision 1: published by Daiwei on