Constructor Public Methods

Benchmark created by Nicolas on


Description

Using prototype public methods vs. initialize public methods in a function constructor.

Preparation HTML

<script>
  function ConstructorPublicMethods() {
   this.publicMethod1 = function(n) {
    return 2 * n;
   };
  
   this.publicMethod2 = function(n) {
    return 3 * n;
   };
  }
  
  function PrototypePublicMethods() {}
  
  PrototypePublicMethods.prototype = {
   publicMethod1: function(n) {
    return 2 * n;
   },
  
   publicMethod2: function(n) {
    return 3 * n;
   }
  };
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
instanciate constructor public methods
for (var i = 0; i < 1000; i++) {
 new ConstructorPublicMethods();
}
ready
instanciate prototype public methods
for (var i = 0; i < 1000; i++) {
 new PrototypePublicMethods();
}
ready

Revisions

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

  • Revision 1: published by Nicolas on