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);
  • Basic function

     
    function Point(x, y){
        return {
            x, 
            y, 
        };
    }
    const add = (pointa, pointb) =>({ x: pointa.x + pointb.x, y: pointb.y + pointb.y });
    const sub = (pointa, pointb) =>({ x: pointa.x - pointb.x, y: pointa.y - pointb.y });
    var p1 = Point(10, 10);
    var p2 = Point(10, -10);
    var sum = add(p1, p2);
    var dif = sub(p1, p2);
  • Basic functions with object destructuring

     
    function Point(x, y){
        return {
            x, 
            y, 
        };
    }
    const add = ({ x:xa, y:ya }, { x:xb, y:yb }) =>({ x: xa + xb, y: ya + yb });
    const sub = ({ x:xa, y:ya }, { x:xb, y:yb }) =>({ x: xa - xb, y: ya - yb });
    var p1 = Point(10, 10);
    var p2 = Point(10, -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
    Basic function
    Basic functions with object destructuring

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: one year ago)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15
Safari 17 on Mac OS X 10.15.7
View result in a separate tab
Test name Executions per second
ES6 Class 3524369.0 Ops/sec
Function Prototype 4096837.5 Ops/sec
Object Literal 2365982.8 Ops/sec
Basic function 65396164.0 Ops/sec
Basic functions with object destructuring 63556236.0 Ops/sec