Define property vs define properties

Benchmark created by PeteA 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, 'height', {
  get: function() {
    return this.height;
  },
  set: function(h) {
    this.height = Number(h);
  }
});
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);
    }
  }
});
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);
  }
}
ready

Revisions

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