Object.create vs Factory

Benchmark created by Enzo on


Setup

var obj = {
        a: 1,
        b: "b",
        c: false,
        fun: function() {return this.a;}
    };
    
    var factory = function() {
        return {
            a: 1,
            b: "b",
            c: false,
            fun: factory.fun
        };
    };
    factory.fun = function() {return this.a;}
    
    
    var constructor = function() {
        this.a = 1;
        this.b = "b";
        this.c = false;
    };
    constructor.prototype.fun = function() {return this.a;}

Test runner

Ready to run.

Testing in
TestOps/sec
Object.create
var cre = Object.create(obj);
ready
Factory
var fac = factory();
ready
New
var con = new constructor();
ready
Object.create fun()
var cre = Object.create(obj);
cre.fun();
ready
Factory fun()
var fac = factory();
fac.fun();
ready
New fun()
var con = new constructor();
con.fun();
ready

Revisions

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