Object.create vs Crockford vs Constructor (v33)

Revision 33 of this benchmark created by A. Matías Quezada 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 shared() { }
  shared.prototype = sharedPrototype;

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

  function Constructor() { }
  Constructor.prototype = new shared();
  Constructor.prototype.one = function() { return 1; };
  Constructor.prototype.two = function() { return 2; };
  Constructor.prototype.three = function() { return 3; };
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Object.create()
Object.create(sharedPrototype);
ready
Crockford Create
crockfordCreate(sharedPrototype);
ready
Constructor
new Constructor;
ready

Revisions

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