Object.defineProperty vs __defineGetter__ vs normal (v9)

Revision 9 of this benchmark created by Fábio Miranda Costa on


Description

Test different access method to an object property

Preparation HTML

<script>
  obj = {
   _x: 0
  }
  
  funct = {
   get: function() {
    return this._x
   },
   set: function(value) {
    this._x = value
   }
  }

obj = {
   _x: 0
};

Object.defineProperty(obj, "x", {
 get: funct['get'],
 set: funct['set']
});

var X = function() {
  this._x = 0;
};
X.prototype.get = funct.get;
X.prototype.set = funct.set;

obj2 = new X();

</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Object.defineProperty
var x;
for (var i = 0; i < 1000; i++) {
 x = obj.x;
}
ready
Function
var x;
for (var i = 0; i < 1000; i++) {
 x = obj2.get();
}
ready

Revisions

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