Object.create() vs. constructor vs. object literal (v107)

Revision 107 of this benchmark created on


Preparation HTML

<script>
    Obj = function () {
        this.p = 1;
    };

    ObjLiteral = function() {
        return { p: 1 };
    };

    wrapper = function () {
        return new Obj();
    };

    propObj = {
        p: {
            value: 1
        }
    };

    Obj.prototype.create = function () {
        return new Obj();
    };
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Object.create() using in-place property object
o = Object.create(Object.prototype, {
  p: {
    value: 1
  }
});
ready
Object.create() using pre-defined property object
o = Object.create(Object.prototype, propObj);
ready
Constructor function
o = new Obj();
ready
Constructor wrapper
o = wrapper();
ready
Prototype pattern with constructor wrapper
o = Obj.prototype.create();
ready
Literal wrapper
o = ObjLiteral();
ready

Revisions

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