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

     
    function Point(x, y){
        this.x = x;
        this.y = y;
    }
    Point.prototype.add = function(point){
        return new Point(this.x + point.x, this.y + point.y);
    }
    Point.prototype.sub = function(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);
  • 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);
  • Object Literal & Function

     
    const add = (a, b) => ({ x: a.x + b.x, y: a.y + b.y });
    const sub = (a, b) => ({ x: a.x - b.x, y: a.y - b.y });
    var p1 = { x: 10, y: 10 };
    var p2 = { x: 10, y: -10 };
    var sum = add(p1, p2);
    var dif = sub(p1, p2);
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    ES6 Class
    Function Prototype
    Object Literal
    Object Literal & Function

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 8 days ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36 Edg/133.0.0.0
Chrome 133 on Windows
View result in a separate tab
Test name Executions per second
ES6 Class 842472.6 Ops/sec
Function Prototype 741919.7 Ops/sec
Object Literal 2362710.2 Ops/sec
Object Literal & Function 226168048.0 Ops/sec