Script Preparation code:
x
 
class PointClass {
    constructor(x, y){
        this.x = x;
        this.y = y;
    }
    add(point){
        return new PointClass(this.x + point.x, this.y + point.y);
    }
    sub(point){
        return new PointClass(this.x - point.x, this.y - point.y);
    }
}
function PointProto(x, y){
    this.x = x;
    this.y = y;
}
PointProto.prototype.add = function(point){
    return new PointProto(this.x + point.x, this.y + point.y);
}
PointProto.prototype.sub = function(point){
    return new PointProto(this.x - point.x, this.y - point.y);
}
function PointFactory(x, y){
    return {
        x, 
        y, 
        add: (point)=>PointFactory(this.x + point.x, this.y + point.y),
        sub: (point)=>PointFactory(this.x - point.x, this.y - point.y)
    }  
}
window.PointClass = PointClass
window.PointProto = PointProto
window.PointFactory = PointFactory
window.num = 10_000
Tests:
  • ES6 Class

     
    const points = []
    for (let index = 0; index < num; index++) {
      points.push(new PointClass(10, 10))
    }
  • Function Prototype

     
    const points = []
    for (let index = 0; index < num; index++) {
      points.push(new PointProto(10, 10))
    }
  • Object Literal

     
    const points = []
    for (let index = 0; index < num; index++) {
      points.push(PointFactory(10, 10))
    }
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    ES6 Class
    Function Prototype
    Object Literal

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: one year ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36
Chrome 114 on Windows
View result in a separate tab
Test name Executions per second
ES6 Class 314.2 Ops/sec
Function Prototype 406.2 Ops/sec
Object Literal 379.3 Ops/sec