Object.create vs Crockford vs Jorge vs Constructor (v9)

Revision 9 of this benchmark created on


Preparation HTML

<script>
  var sharedPrototype = {
   one: function() {
    return 1;
   },
   two: function() {
    return 2;
   },
   three: function() {
    return 3;
   }
  };
  
  var crockfordCreate = function(proto) {
   var f = function() {};
   f.prototype = proto;
   return new f();
  };
  
  var jorgeCreate = (function() {
   var f = function() {};
   return function(proto) {
    f.prototype = proto;
    return new f();
   };
  })();
  
  var Constructor = function() {};
  Constructor.prototype = 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
Jorge Create
var i = 100;
while (i--) jorgeCreate(sharedPrototype);
ready
Constructor
var i = 100;
while (i--) new Constructor;
ready

Revisions

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