Prototype vs Module pattern performance (v231)

Revision 231 of this benchmark created on


Description

Use a factory function without Object.create() for standardobject

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 factory = {
      create: function() {
        return {
          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
Standard object with factory function
var o = factory.create()
o.bar;
o.foo;
ready

Revisions

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