new vs Object.create (including polyfill) && polypill (v12)

Revision 12 of this benchmark created on


Description

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


Added the polyfill even when is not needed. Also a function with some data.

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

function polyfill_create(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 Foo = function() {};
  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
polyfill_create
var obj = polyfill_create(Foo.prototype)
ready

Revisions

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