Object.defineProperty vs __defineGetter__ vs normal (v54)

Revision 54 of this benchmark created on


Description

Test different access method to an object property

Preparation HTML

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

Test runner

Ready to run.

Testing in
TestOps/sec
Object.defineProperty
Object.defineProperty(obj, "x", {
 get: funct['get'],
 set: funct['set']
})
 
ready
__defineGetter__
obj.__defineGetter__('x', funct['get']);
obj.__defineSetter__('x', funct['set']);
 
ready
Normal
 
ready
Prototype
obj.prototype = {
 get x() {
  return this._x;
 }, set x(value) {
  this_x = value;
 }
}
 
ready
Setter
obj.setX = function(value) {
 this._x = value;
}
 
ready

Revisions

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