Define property vs define properties (v6)

Revision 6 of this benchmark created by devu on


Description

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

Combined with calls using those methods

Test runner

Ready to run.

Testing in
TestOps/sec
defineProperty
var objA = function() {};
Object.defineProperty(objA.prototype, 'width', {
  get: function() {
    return this.width;
  },
  set: function(v) {
    this.width = v;
  }
});
Object.defineProperty(objA.prototype, 'height', {
  get: function() {
    return this.height;
  },
  set: function(v) {
    this.height = v;
  }
});
Object.defineProperty(objA.prototype, 'area', {
  get: function() {
    return this.area;
  },
  set: function(v) {
    this.area = area;
  }
});

for (var i = 0; i < 10; i++) {
  var w = objA.width;
  var h = objA.height;
  objA.area = w * h;
}
ready
defineProperties
var objB = function() {};
Object.defineProperties(objB.prototype, {
  width: {
    get: function() {
      return this.width;
    },
    set: function(v) {
      this.width = v;
    }
  },
  height: {
    get: function() {
      return this.height;
    },
    set: function(v) {
      this.height = v;
    }
  },
  area: {
    get: function() {
      return this.area;
    },
    set: function(v) {
      this.area = v;
    }
  }
});

for (var i = 0; i < 10; i++) {
  var w = objB.width;
  var h = objB.height;
  objB.area = w * h;
}
ready
getter
var objC = function() {};
objC.prototype = {
  get width() {
    return this.width;
  },
  set width(v) {
    this.width = v;
  },
  get height() {
    return this.height;
  },
  set height(v) {
    this.height = v;
  },
  get area() {
    return this.height;
  },
  set area(v) {
    this.height = v;
  }
}

for (var i = 0; i < 10; i++) {
  var w = objC.width;
  var h = objC.height;
  objC.area = w * h;
}
ready

Revisions

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