Prototype vs Module pattern performance (v230)

Revision 230 of this benchmark created on


Description

Use a factory function 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 standardObject = {
      foo: function() {},
      bar: function() {}
    };
    var factory = {
      create: function() {
        return Object.create(standardObject);
      }
    }

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.