prototype vs closures (v86)

Revision 86 of this benchmark created by tav on


Setup

function Person(name, location) {
  	this.name = name;
    this.location = name + "lives at: " + location;
  }
  
  Person.prototype.getinfo = function() {
  	return this.name + "/" + this.location;
  };
  
  Person.prototype.setinfo = function(name, location) {
  	this.name = name;
    this.location = name + "lives at: " + location;
  };
  
  var person = function(name, location) {
  	return {
  		'getinfo': function() {
      	return this.name + "/" + this.location;
  		},
  		'setinfo': function(n, l) {
      	name = n;
        location = n + "lives at: " + l;
  		}
  	};
  };
  
  var operson = function(name, location) {
    return {name: name, location: location};
  };
  
  var getInfo = function(p) {
  	return p.name + "/" + p.location;
  }
  
  var setInfo = function(p, name, location) {
  	p.name = name;
    p.location = name + "lives at: " + location;
  }
  
  var _p = new Person('John', 'London');
  var _c = person('John', 'London');
  var _o = operson('John', 'London');

Test runner

Ready to run.

Testing in
TestOps/sec
Prototype init
var p = new Person('John', 'London');
ready
Closure init
var c = person('John', 'London');
ready
Prototype read
_p.getinfo();
ready
Closure read
_c.getinfo();
ready
Prototype write
_p.setinfo('Jane', 'Paris');
ready
Closure write
_c.setinfo('Jane', 'Paris');
ready
Obj init
var o = operson('John', 'London');
ready
Obj read
getInfo(_o);
ready
Obj write
setInfo(_o, 'Jane', 'Paris');
ready

Revisions

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