Object.create vs Crockford vs Constructor (v32)

Revision 32 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;
    }
  };

  var crockfordCreate = function(o) {
      function F() {}
      F.prototype = o;
      return new F();
      };

  var Constructor = function() {
      this.one = function() {
        return 1;
      };
      this.two = function() {
        return 2;
      };
      this.three = function() {
        return 3;
      }

      return this;
      };
  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
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.