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 pointParent = {
          add(point) {
              return pointNew(this.x + point.x, this.y + point.y);
            }
        };
        const pointParentParent = {
          sub(point) {
              return pointNew(this.x + point.x, this.y + point.y);
            }
        };
        Object.setPrototypeOf(pointParent, pointParentParent);
        function pointNew (x, y) {
          let p = {
            x:x,
            y:y
          }
          Object.setPrototypeOf(p, pointParent);
          return p
        }
        
        let a1 = pointNew(10, 10);
        let a2 = pointNew(10, -10);
        let sum = a1.add(a2);
        let dif = a1.sub(a2);
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 438241.3 Ops/sec
Object Literal 278029.9 Ops/sec