prototype vs closures (v68)

Revision 68 of this benchmark created on


Setup

function ProtoPerson(name) {
  	this.name = name;
  }
  
  ProtoPerson.prototype.get_name = function() {
  	return this.name;
  };
  
  ProtoPerson.prototype.set_name = function(name) {
  	this.name = name;
  };
  
  var ObjPerson = function(pname) {
  	return {
  		'get_name': function() {
   			return pname;
   		},
  		'set_name': function(name) {
  		 	pname = name;
  		}
  	};
  };
  
  var ClosPerson = function(name) {
    this.set_name = function(n) {
      name=n;
    };
    this.get_name = function() {
      return name;
    };
  }
  
  var _p = new ProtoPerson('John');
  var _o = ObjPerson('John');
  var _c = new ClosPerson('John');

Test runner

Ready to run.

Testing in
TestOps/sec
Prototype get
_p.get_name();
ready
Closure get
_c.get_name();
ready
Prototype set
_p.set_name('Jane');
ready
Closure set
_c.set_name('Jane');
ready
Plain Object get
_o.get_name();
ready
Plain Object set
_o.set_name('Jane');
ready
new Prototype
var dummyp = new ProtoPerson('James');
ready
new Closure
var dummyc = new ClosPerson('James');
ready
new plain Object
var dummyo = ObjPerson('James');
ready

Revisions

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