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

Revision 10 of this benchmark created on


Preparation HTML

<script>
  var A = function() {
      this._x = 0;
      };
  
  var B = function() {
      this._z = 0;
      };
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Object.create() using in-place property object
A.prototype = Object.create(Object.prototype, {
  x: {
    get: function() {
      return this._x;
    },
    set: function(v) {
      this._x = v;
    }
  }
});

B.prototype = Object.create(A.prototype, {
  foo: {
    value: function() {;
    }
  }
});

var b = new B();
ready
Object.create() using pre-defined property object
var _x = {
  x: {
    get: function() {
      return this._x;
    },
    set: function(v) {
      this._x = v;
    }
  }
};

var _foo = function() {;
    };

A.prototype = Object.create(Object.prototype, {
  x: _x
});

B.prototype = Object.create(A.prototype, {
  foo: {
    value: _foo
  }
});

var b = new B();
ready
Constructor function
A.prototype = {
  get: function() {
    return this._x;
  },
  set: function(v) {
    this._x = v;
  }
};

B.prototype = new A();
B.prototype.constructor = B;

B.prototype.foo = function() {;
};

var b = new B();
ready

Revisions

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