Prototype vs Module pattern performance

JavaScript performance comparison

Revision 54 of this test case created by Aaron

Preparation code

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


Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
var o = new TraditionalPrototypeClass();;
Module pattern
var o = new ModulePatternClass();;
Module pattern with cached functions
var o = new ModuleCachePatternClass();;
Use the right tool for the job
var o = standardObject;;;

Compare results of other browsers


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


Montana Harkin commented :

Your "right tool" test case isn't actually creating a new object. See my revision.

aa commented :

AlexWindHope commented :

If your goal is to just have couple static stateless functions than nobody except maybe some beginners will actually create an object, also - this test isn't really correct cause even if you will use class or module you're unlikely going to allocate new object for each propertie read, overall this test is just an epic facepalm