Object.create vs Crockford vs Constructor

JavaScript performance comparison

Revision 45 of this test case created by

Preparation code

<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>
      
<script>
Benchmark.prototype.setup = function() {
  arr
  arr2
  arr3

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/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()});
pending…
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()});




pending…
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()});

pending…

Compare results of other browsers

Revisions

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

0 Comments