Object.defineProperty vs __defineGetter__ vs normal (v67)

Revision 67 of this benchmark created by Digitale Welten on


Description

Test different access method to an object property

Preparation HTML

<script>
var ns = (function(ns){

  ns.obj = {
   _x: 0
  }
  
  function Class() {
    this.x = 0
  }

  function Proto() {
    this.x = 0
  }
  Proto.prototype.get = function(){
    return this.x;
  };
  Proto.prototype.set = function(val){
    this.x = val;
  };

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

ns.p = new ProtoDefineInner()
ns.p1 = new Class();
ns.p2 = new Proto();

return ns;

}({}));
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Object.defineProperty
ns.p.x = Math.random();
var y = ns.p.x;
 
ready
Normal Class
ns.p1.x = Math.random();
var y = ns.p1.x;
ready
normal object
ns.obj._x = Math.random();
var y = ns.obj._x;
ready
Normal Prototype
ns.p2.set(Math.random());
var y = ns.p2.get();
ready

Revisions

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