Prototype vs Module Pattern (v188)

Revision 188 of this benchmark created on


Description

This test case focuses solely on pattern variations of creating a "Class".

No work is done in each case, just access, leaving the 'perf' to be determined by which pattern creates it's "Class" fastest.

Sometimes, less is more.

Preparation HTML

<script>
//Assign 'KlassX' Pattern to 'tmp' in each test
var tmp;

//
// Prototypal
//
function Klass1 () {}
Klass1.prototype = {
    foo : function () {},
    bar : function () {}
};

//
// Module Pattern
//
function Klass2 () {
    return {
        foo: function() {},
        bar: function() {}
    };
}

//
// Module Pattern Utilizing Cached Functions
//
var functionFoo = function() {},
    functionBar = function() {};
function Klass3 () {
        return {
                foo: functionFoo,
                bar: functionBar
        };
}
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Prototypal
tmp = new Klass1();
tmp.foo();
tmp.bar();
ready
Module Pattern
tmp = Klass2();
tmp.foo();
tmp.bar();
ready
Module Pattern Utilizing Cached Functions
tmp = Klass3();
tmp.foo();
tmp.bar();
ready

Revisions

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