Prototype vs Module pattern performance (v54)

Revision 54 of this benchmark created by Aaron on


Setup

function TraditionalPrototypeClass() {
  }
  
  TraditionalPrototypeClass.prototype.foo = function() {
  };
  
  TraditionalPrototypeClass.prototype.bar = function() {
  };
  
  function ModulePatternClass() {
      this.foo = function() {
      };
      
      this.bar = function() {
      };
  }
  
  var ModuleCachePatternClass = (function () {
      function foo() {
      }
      
      function bar() {
      }
      
      return function () {
          this.foo = foo;
          this.bar = bar;
      };
  }());
  
  var standardObject = {
      foo: function(){
      },
      bar: function(){
      }
  };

Test runner

Ready to run.

Testing in
TestOps/sec
Prototypal
var o = new TraditionalPrototypeClass()
o.bar;
o.foo;
ready
Module pattern
var o = new ModulePatternClass()
o.bar;
o.foo;
ready
Module pattern with cached functions
var o = new ModuleCachePatternClass()
o.bar;
o.foo;
ready
Use the right tool for the job
var o = standardObject;
o.bar;
o.foo;
ready

Revisions

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