new vs Object.create (including polyfill) (v2)

Revision 2 of this benchmark created by gero3 on


Description

testing of new vs native object.create when supported or polyfill where needed

Preparation HTML

<script>
  if (typeof Object.create !== 'function') {
   Object.create = function(o, props) {
    function F() {}
    F.prototype = o;
  
    if (typeof(props) === "object") {
     for (prop in props) {
      if (props.hasOwnProperty((prop))) {
       F[prop] = props[prop];
      }
     }
    }
    return new F();
   };
  }
  var GeometryCount  = 0;
  var Foo = function() {
        this.id = GeometryCount ++;

        this.vertices = [];
        this.colors = []; // one-to-one vertex colors, used in ParticleSystem, Line and Ribbon

        this.materials = [];

        this.faces = [];

        this.faceUvs = [[]];
        this.faceVertexUvs = [[]];

        this.morphTargets = [];
        this.morphColors = [];
        this.morphNormals = [];

        this.skinWeights = [];
        this.skinIndices = [];

        this.boundingBox = null;
        this.boundingSphere = null;

        this.hasTangents = false;

        this.dynamic = false; // unless set to true the *Arrays will be deleted once sent to a buffer.
};
  Foo.prototype.bar = "bar";
  Foo.prototype.baz = "baz";
  Foo.prototype.bang = "bang";
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
New
var obj = new Foo();
ready
Object.create
var obj = Object.create(Foo.prototype)
ready

Revisions

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