Tests:
  • ES6 Class

    x
     
    class Point {
        constructor(x, y){
            this.x = x;
            this.y = y;
        }
        add(point){
            return new Point(this.x + point.x, this.y + point.y);
        }
        sub(point){
            return new Point(this.x - point.x, this.y - point.y);
        }
    }
    var p1 = new Point(10, 10);
    var p2 = new Point(10, -10);
    var sum = p1.add(p2);
    var dif = p1.sub(p2);
  • Function Prototype with longer chain

     
    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

     
    function Point(x, y){
        return {
            x, 
            y, 
            add: (point)=>Point(this.x + point.x, this.y + point.y),
            sub: (point)=>Point(this.x - point.x, this.y - point.y)
        }  
    }
    var p1 = Point(10, 10);
    var p2 = Point(10, -10);
    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
    ES6 Class
    Function Prototype with longer chain
    Object Literal

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: one year ago)
Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0
Firefox 115 on Ubuntu
View result in a separate tab
Test name Executions per second
ES6 Class 755218.4 Ops/sec
Function Prototype with longer chain 526179.1 Ops/sec
Object Literal 1490133.5 Ops/sec