Object.create vs Crockford vs Constructor (v45)

Revision 45 of this benchmark created on


Description

Wondering how much of a difference hoisting f out of crockfordCreate will make.

Preparation HTML

<script>
  var sharedPrototype = {
   one: function() {
    return 1;
   },
   two: function() {
    return 2;
   },
   three: function() {
    return 3;
   }
  };
  
  function F() {}
  var crockfordCreate = function(proto) {
   F.prototype = proto;
   return new F();
  };
  
  var Constructor = function() {};
  Constructor.prototype = sharedPrototype;
</script>

Setup

arr
    arr2
    arr3

Test runner

Ready to run.

Testing in
TestOps/sec
Object.create()
var arr = [];
var arr2=[];
var arr3=[];
var i = 30000;


while (i--) arr.push(Object.create(sharedPrototype));


arr2=arr.map(function(e){return e.two()});
arr3=arr.map(function(e){return e.three()});
ready
Crockford Create
var arr = [];
var arr2=[];
var arr3=[];

var i = 30000;

while (i--)  arr.push(crockfordCreate(sharedPrototype));


arr2=arr.map(function(e){return e.two()});
arr3=arr.map(function(e){return e.three()});




 
ready
Constructor
var arr = [];
var arr2=[];
var arr3=[];

var i = 30000;

while (i--)  arr.push(new Constructor);


arr2=arr.map(function(e){return e.two()});
arr3=arr.map(function(e){return e.three()});

 
ready

Revisions

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