Class vs prototype with child class

Benchmark created on


Setup

function Parent(x) {
  this.x = x;
}
Parent.prototype.get_x = function() {
  return this.x;
};
Child.prototype = Object.create(Parent.prototype);

function Child(x, y) {
  Parent.call(this, x);
  this.y = y;
}
Child.prototype.get_y = function() {
  return this.y;
};
class Parentc {
  constructor(x) {
    this.x = x;
  }
  get_x() {
    return this.x;
  }
}
class Childc extends Parentc {
  constructor(x, y) {
    super(x);
    this.y = y;
  }
  get_y() {
    return this.y;
  }
}   

Test runner

Ready to run.

Testing in
TestOps/sec
Prototype
var child = new Child(1, 2);
child.get_x() + child.get_y(); 
ready
Class
var childc = new Childc(1, 2);
childc.get_x() + childc.get_y();   
ready

Revisions

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