Prototype vs Module pattern access performance

JavaScript performance comparison

Revision 56 of this test case created

Info

access performance test.

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() {}
    };
   
    var o1 = new TraditionalPrototypeClass();
    var o2 = new ModulePatternClass();
    var o3 = new ModuleCachePatternClass();
    var o4 = {
      foo: function() {},
      bar: function() {}
    };
   
};
</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Prototypal
o1.bar;
o1.foo;
pending…
Module pattern
o2.bar;
o2.foo;
pending…
Module pattern with cached functions
o3.bar;
o3.foo;
pending…
Use the right tool for the job
o4.bar;
o4.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. Here’s a list of current revisions for this page:

0 comments

Add a comment