Object.create vs Shim

JavaScript performance comparison

Revision 2 of this test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var p = {
      test: function() {
        return Math.random();
      }
    }
   
    //var native = Object.create(p);
   
    function objCreate(p) {
      return Object.create(p);
    }
   
    function shim(p) {
      function f() {};
      f.prototype = p;
      return new f();
    }
    //var shim = new Shim();
   
    var subclass = {};
};
</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
Native
subclass.prototype = Object.create(p);
pending…
Shim
subclass.prototype = shim(p);
pending…
Object.create with function overhead
subclass.prototype = objCreate(p);
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