Factory vs Prototype

Benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
Factory
function createValueObject(value) {
  return {
    get: function() { return value; }
  };
}

for (let i = 0; i < 10000; i++) {
	const valueObject = createValueObject("Hola!")
	valueObject.get();	
}
ready
Prototype
function ValueObject(value) {
  this.value = value;
}

ValueObject.prototype.get = function() {
  return this.value;
};

for (let i = 0; i < 10000; i++) {
	const valueObject = new ValueObject("Hola!")
	valueObject.get();
}
ready

Revisions

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