Prototype vs Module pattern performance (v184)

Revision 184 of this benchmark created on


Description

Actually create new objects for the "standard" test.

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 = {
  foo: function() {},
  bar: function() {}
};
o.bar;
o.foo;
ready

Revisions

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