Prototype vs Module pattern performance (v216)

Revision 216 of this benchmark created on


Description

Testing properties with values, rather than functions

Setup

function TraditionalPrototypeClass() {
    }
    
    TraditionalPrototypeClass.prototype.foo = [1,2,3];
    
    TraditionalPrototypeClass.prototype.bar = [1,2,3];
    
    function ModulePatternClass() {
        this.foo = [1,2,3];
        
        this.bar = [1,2,3];
    }
    
    var ModuleCachePatternClass = (function () {
        var foo = [1,2,3];
        
        var bar = [1,2,3];
        
        return function () {
            this.foo = foo;
            this.bar = bar;
        };
    }());
    
    var standardObject = Object.seal({
        foo: [1,2,3],
        bar: [1,2,3]
    });

Test runner

Ready to run.

Testing in
TestOps/sec
Prototypal
var o = new TraditionalPrototypeClass()
o.bar[1];
o.foo[1];
ready
Module pattern
var o = new ModulePatternClass()
o.bar[1];
o.foo[1];
ready
Module pattern with cached functions
var o = new ModuleCachePatternClass()
o.bar[1];
o.foo[1];
ready
Use the right tool for the job
var o = Object.create(standardObject);
o.bar[1];
o.foo[1];
ready

Revisions

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