Define property vs define properties (v4)

Revision 4 of this benchmark created on


Description

Checking Object.defineProperty against Object.defineProperties in a 'realistic' code environment

Test runner

Ready to run.

Testing in
TestOps/sec
defineProperty
var obj = function() {};
Object.defineProperty(obj.prototype, 'width', {
  get: function() {
    return this.width_;
  },
  set: function(w) {
    this.width_ = Number(w);
  }
});

Object.defineProperty(obj.prototype, 'height', {
  get: function() {
    return this.height_;
  },
  set: function(h) {
    this.height_ = Number(h);
  }
});
var o1 = new obj();
o1.width = 1;
o1.height = 1;
o1.width;
o1.height;
ready
defineProperties
var obj = function() {};
Object.defineProperties(obj.prototype, {
  width: {
    get: function() {
      return this.width_;
    },
    set: function(w) {
      this.width_ = Number(w);
    }
  },
  height: {
    get: function() {
      return this.height_;
    },
    set: function(h) {
      this.height_ = Number(h);
    }
  }
});
var o1 = new obj();
o1.width = 1;
o1.height = 1;
o1.width;
o1.height;
ready
getter
var obj = function() {};
obj.prototype = {
  get width() {
    return this.width_;
  },
  set width(w) {
    this.width_ = Number(w);
  },
  get height() {
    return this.height_;
  },
  set height(h) {
    this.height_ = Number(h);
  }
};
var o1 = new obj();
o1.width = 1;
o1.height = 1;
o1.width;
o1.height;
ready
Object.create
var obj = function() {};
obj.prototype = Object.create(Object.prototype, {
  width: {
    get: function() {
      return this.width_;
    },
    set: function(w) {
      this.width_ = Number(w);
    }
  },
  height: {
    get: function() {
      return this.height_;
    },
    set: function(h) {
      this.height_ = Number(h);
    }
  }
});
var o1 = new obj();
o1.width = 1;
o1.height = 1;
o1.width;
o1.height;
ready

Revisions

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