Object.defineProperty vs __defineGetter__ vs normal (v58)

Revision 58 of this benchmark created by Chedwick on


Description

Test different access method to an object property

Preparation HTML

<script>
  obj = {
   _x: 0
  }
  
  function Proto() {
    this.x = 0
  }

  function ProtoDefineInner() {
        var _x = 0
    Object.defineProperty(this, 'x', {
                get: function () { return _x },
                set: function (val) { _x = val }
        }) 
  }

var p = new ProtoDefineInner()
var p1 = new Proto();
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Object.defineProperty
for (var i = 0; i < 10000; i++) {
  p.x = i;
}

for (var i = 0; i < 10000; i++) {
  var y = p.x;
}
ready
Normal prototype
for (var i = 0; i < 10000; i++) {
  p1.x = i;
}

for (var i = 0; i < 10000; i++) {
  var y = p1.x;
}
ready
normal object
for (var i = 0; i < 10000; i++) {
  obj._x = i;
}

for (var i = 0; i < 10000; i++) {
  var y = obj._x;
}
ready

Revisions

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