js class vs proto

Benchmark created by angeal185 on


Test runner

Ready to run.

Testing in
TestOps/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();
ready
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();
ready

Revisions

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

  • Revision 1: published by angeal185 on