Tests:
  • Function Prototype

    x
     
    function Point(x, y){
      this.x = x;
      this.y = y;
    }
    const pointParent = {
      add(point) {
        return new Point(this.x + point.x, this.y + point.y);
      }
    };
    const pointParentParent = {
      sub(point) {
        return new Point(this.x + point.x, this.y + point.y);
      }
    };
    Object.setPrototypeOf(pointParent, pointParentParent);
    Point.prototype = pointParent;
     var p1 = new Point(10, 10);
     var p2 = new Point(10, -10);
     var sum = p1.add(p2);
     var dif = p1.sub(p2);
  • Object Literal

     
    const point = (x, y) => {
      return {
        x:x,
        y:y
      }
    }
    const pointParent = {
      add(pointc) {
        return Object.setPrototypeOf(point(this.x + pointc.x, this.y + pointc.y), pointParent);
      }
    };
    const pointParentParent = {
      sub(pointc) {
        return Object.setPrototypeOf(point(this.x + pointc.x, this.y + pointc.y), pointParent);
      }
    };
    Object.setPrototypeOf(pointParent, pointParentParent);
    var p1 = Object.setPrototypeOf(point(10,10), pointParent);
    var p2 = Object.setPrototypeOf(point(10,-10), pointParent);
    var sum = p1.add(p2);
    var dif = p1.sub(p2);
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Function Prototype
    Object Literal

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: one year ago)
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36
Chrome 106 on Linux
View result in a separate tab
Test name Executions per second
Function Prototype 457756.2 Ops/sec
Object Literal 270245.9 Ops/sec