Prototype vs Module pattern performance

JavaScript performance comparison

Revision 84 of this test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  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() {}
  };

};
</script>

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
Prototypal
var o = new TraditionalPrototypeClass()
o.bar;
o.foo;
pending…
Module pattern
var o = new ModulePatternClass()
o.bar;
o.foo;
pending…
Module pattern with cached functions
var o = new ModuleCachePatternClass()
o.bar;
o.foo;
pending…
Use the right tool for the job
var o = {
  foo: function() {},
  bar: function() {}
};
o.bar;
o.foo;
pending…

Compare results of other browsers

Revisions

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

0 Comments