Object.create vs Crockford vs Constructor (v29)

Revision 29 of this benchmark created on


Preparation HTML

<script>
  var sharedPrototype = {
    one: function() {
      return 1;
    },
    two: function() {
      return 2;
    },
    three: function() {
      return 3;
    }
  };

  var rodrigoCreate = function() {
      return new Constructor;
      };

  var crockfordCreate = function(proto) {
      var f = function() {};
      f.prototype = proto;
      return new f();
      };

  var Constructor = function() {};
  Constructor.prototype = sharedPrototype;

  var cornfordCreate = (function() {
    var f = function() {};
    return function(proto) {
      f.prototype = proto;
      return new f();
    };
  })();

  var cachedCornfordCreate = function(proto) {
      var f = function() {};
      f.prototype = proto;
      return function() {
        return new f();
      };
      };

  var cornfordCreate2 = cachedCornfordCreate(sharedPrototype);
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Object.create()
var i = 100;
while (i--) Object.create(sharedPrototype);
ready
Crockford Create
var i = 100;
while (i--) crockfordCreate(sharedPrototype);
ready
Constructor
var i = 100;
while (i--) new Constructor;
ready
Proto
var i = 100
while (i--) {
  ({
    '__proto__': Constructor
  })
}
ready
Cornford Create
var i = 100;
while (i--) cornfordCreate(sharedPrototype);
ready
Rodrigo Create
var i = 100;
while (i--) rodrigoCreate();
ready
Cached Cornford Create
var i = 100;
while (i--) cornfordCreate2();
ready
Rodrigo Nery Objeto
var i = 100;
while (i--) var objeto = objeto || {};
ready

Revisions

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