prototype vs closures (v37)

Revision 37 of this benchmark created on


Setup

function Person(name) {
  	this.name = name;
  }
  
  Person.prototype.get_name = function() {
  	return this.name;
  };
  
  Person.prototype.set_name = function(name) {
  	this.name = name;
  };
  
  var person = function(name) {
  	var p = {
  		name: name
  	};
  
  	return {
  		'get_name': function() {
  			return p.name;
  		},
  		'set_name': function(name) {
  			p.name = name;
  		}
  	};
  };
  
  var _p = [];
  var _c = [];
  var i;
  for (i = 0; i < 10000; ++i) {
    _p.push(new Person('John'));
    _c.push(person('John'));
  }

Test runner

Ready to run.

Testing in
TestOps/sec
Prototype read
var i;
for (i = 0; i < _p.length; ++i) {
  _p[i].get_name();
}
ready
Closure read
var i;
for (i = 0; i < _c.length; ++i) {
  _c[i].get_name();
}
ready

Revisions

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