Subclassing via Object.create or new

JavaScript performance comparison

Test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  function constructor (x,y) {
  this.x = x;
  this.y = y;
  }
  
  constructor.prototype.add = function (x,y) {
  this.x += x;
  this.y += y;
  }
  
  function subClass() {
  }
  
  function tempCtor() {
  }

};
</script>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Object.create
subClass.prototype = Object.create(constructor.prototype);
pending…
New with dummy constructor
tempCtor.prototype = constructor.prototype;
subClass.prototype = new tempCtor();
pending…
New
subClass.prototype = new constructor();
pending…

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

Compare results of other browsers

0 Comments