prototype vs closures (v75)

Revision 75 of this benchmark created on


Setup

function Person(name, getter, setter) {
  	  this.name = name;
      if (getter) this.getName = getter.bind(this);
      if (setter) this.setName = setter.bind(this);
  }
  Person.prototype.getName = function(){ return this.name; };
  Person.prototype.setName = function(name){ this.name = name; };
  
  
  var proto = {getName: function(){ return this.name; },
               setName: function(name){ this.name = name; }
  };
  
  var _p = new Person('John');
  var _c = new Person('John', proto.getName, proto.setName);

Test runner

Ready to run.

Testing in
TestOps/sec
Prototype init
var p = new Person('John', proto.getName, proto.setName);
ready
Closure init
var c = Person('John');
ready
Prototype read
_p.getName();
ready
Closure read
_c.getName();
ready
Prototype write
_p.setName('Jane');
ready
Closure write
_c.setName('Jane');
ready

Revisions

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