Object.defineProperty vs __defineGetter__ vs normal (v51)

Revision 51 of this benchmark created on


Description

Test different access method to an object property

Preparation HTML

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

Test runner

Ready to run.

Testing in
TestOps/sec
Object.defineProperty
Object.defineProperty(obj, "x", {
  get: funct['get']
})

for (var i = 0; i < 1000; i++) {
  console.log(obj.x);
}
ready
__defineGetter__
obj.__defineGetter__('x', funct['get']);

for (var i = 0; i < 1000; i++) {
  console.log(obj.x);
}
ready
Normal
obj.x = funct['get']();

for (var i = 0; i < 1000; i++) {
  console.log(obj.x);
}
ready
Prototype
obj.prototype = {
  get x() {
    return this._x;
  }
}

for (var i = 0; i < 1000; i++) {
  console.log(obj.x);
}
ready
get
obj.get x() {
    return this._x;
  }


for (var i = 0; i < 1000; i++) {
  console.log(obj.x);
}
ready
get2
obj."x": {
    get: function {
      return this._x;
    }
  }

for (var i = 0; i < 1000; i++) {
  console.log(obj.x);
}
ready

Revisions

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