js class vs proto

JavaScript performance comparison

Test case created by angeal185

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
class
class Example {
  constructor(height, width) {
    this.area = height * width;
  }
  add(){
    this.area = this.area + 999;
    return this;
  }
  mul(){
    this.area = this.area * 999;
    return this;
  }
  sub(){
    this.area = this.area - 999;
    return this;
  }
  all(){
    return this.area;
  }
}

let x = new Example(4, 3).add().sub().mul().all();
pending…
proto
function Example(height, width){
  this.area = height * width;
}

Example.prototype = {
  add(){
    this.area =  this.area + 999;
    return this;
  },
  mul(){
    this.area = this.area * 999;
    return this;
  },
  sub(){
    this.area = this.area - 999;
    return this;
  },
  all(){
    return this.area;
  }
}

let x = new Example(4, 3).add().sub().mul().all();
pending…

Revisions

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

0 Comments