Prototype vs Module pattern performance

JavaScript performance comparison

Revision 55 of this test case created by Montana Harkin


Actually create new objects for the "standard" test.

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 unknown unknown
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 = {
  foo: function() {},
  bar: function() {}

Compare results of other browsers


You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

1 comment

Jasmine commented :

Great test change! I wish later revisions didn't dirty it up so much.

Comment form temporarily disabled.

Add a comment