Object.create vs Crockford vs Constructor

JavaScript performance comparison

Revision 33 of this test case created by A. Matías Quezada

Info

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

Preparation code

<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

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Object.create()
Object.create(sharedPrototype);
pending…
Crockford Create
crockfordCreate(sharedPrototype);
pending…
Constructor
new Constructor;
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. Here’s a list of current revisions for this page:

0 comments

Add a comment