Prototype vs Module pattern performance

JavaScript performance comparison

Revision 97 of this test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    function Klass () {
    }
    Klass.prototype.foo = function() {
    }
    Klass.prototype.bar = function() {
    }
    Klass.prototype.foo1 = function() {
    }
    Klass.prototype.bar1 = function() {
    }
   
    Klass.prototype.foo2 = function() {
    }
    Klass.prototype.bar2 = function() {
    }
   
    Klass.prototype.foo3 = function() {
    }
    Klass.prototype.bar3 = function() {
    }
    Klass.prototype.foo4 = function() {
    }
    Klass.prototype.bar4 = function() {
    }
   
    function foo() {
    }
   
    function bar() {
    }
   
    function bar1() {
    }
   
    function foo1() {
    }
   
    function foo2() {
    }
   
    function bar2() {
    }
   
    function foo3() {
    }
   
    function bar3() {
    }
   
    function foo4() {
    }
   
    function bar4() {
    }
   
   
    function Klass2 () {
        return {
    foo: foo,
    bar: bar,
    foo1: foo1,
    bar1: bar1,
    foo2: foo2,
    bar2: bar2,
    foo3: foo3,
    bar3: bar3,
    foo4: foo4,
    bar4: bar4
    };
    }
};
</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
var k = new Klass();
k.foo();
k.bar();
 
pending…
Module pattern
var k = new Klass2();
k.foo();
k.bar();
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