Object.create vs. new (v15)

Revision 15 of this benchmark created by Matt Bierner on


Setup

var create = Object.create;
  
  var MyClass = function(x, y) {
    this.x = x;
    this.y = y;
  }
  
  var Factory = function(x, y) {
      return { 'x': x, 'y': y }
  };
  
  var CreateFactory = function(x, y) {
  return create(null, {
  'x': {value: x},
  'y': {value: y}
  });
  };
  
  function doSomething(obj) {
    var x = obj.x + obj.y,
      y = obj.x * obj.y,
      z = obj.x - obj.y;
  
    return x * y * z;
  }
  
  var x = 0 | (Math.random() * 10000),
    y = 0 | (Math.random() * 10000);

Test runner

Ready to run.

Testing in
TestOps/sec
new operator
var obj = new MyClass(x, y);
doSomething(obj);
ready
Factory
var obj = Factory(x, y);
doSomething(obj);
ready
Object.create()
var obj = CreateFactory(x, y);
doSomething(obj);
ready
create()
ready

Revisions

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