Object.defineProperty vs __defineGetter__ vs normal 2 (v6)

Revision 6 of this benchmark created by asnow on


Description

Test different access method to an object property. Here we realy test access to data, and except initialisation function.

Preparation HTML

<script>
  // common data
  var funct = {
   get: function() {
    return this._x
   },
   set: function(value) {
    this._x = value
   }
  }
  // first test data
  var define = {
   _x: 0
  };
  define.__defineGetter__('x', funct['get']);
  define.__defineSetter__('x', funct['set']);
  
  // second test data
  var property = {
   _x: 0
  };
  Object.defineProperty(property, "x", {
   configurable: true,
   get: funct['get'],
   set: funct['set']
  });
  
  // third test data
  var obj = {
   _x: 0
  };
  //fourth test data
  var proto = {
   _x: 0
  };
  proto.prototype = {
   get x() {
    return this._x;
   }, set x(value) {
    this._x = value;
   }
  };
  
  //five test data
  var setter = {
   _x: 0
  };
  setter.setX = function(value) {
   this._x = value;
  };
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
__defineGetter__
var acc = 0;
for (var i = 0; i < 1000; i++) {
 define.x = i;
 acc += define.x;
}
ready
Object.defineProperty
var acc = 0;
for (var i = 0; i < 1000; i++) {
 property.x = i;
 acc += property.x;
}
ready
Normal
var acc = 0;
for (var i = 0; i < 1000; i++) {
 obj._x = i;
 acc += obj._x;
}
ready
Prototype
var acc = 0;
for (var i = 0; i < 1000; i++) {
 proto.x = i;
 acc += proto.x;
}
ready
Setter
var acc = 0;
for (var i = 0; i < 1000; i++) {
 setter.setX(i);
 acc += setter._x;
}
ready

Revisions

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