ES Class vs Prototype

Benchmark created on


Setup

class Point {
    constructor(x, y) {
        this.x = x;
        this.y = y;
    }
    add(b) {
        return new Point(this.x + b.x, this.y + b.y);
    }
}

var PointOld = /** @class */ (function () {
    function PointOld(x, y) {
        this.x = x;
        this.y = y;
    }
    PointOld.prototype.add = function (b) {
        return new PointOld(this.x + b.x, this.y + b.y);
    };
    return PointOld;
}());

Test runner

Ready to run.

Testing in
TestOps/sec
ES Class
new Point(1, 2).add(new Point(3, 4));
ready
Prototype
new PointOld(1, 2).add(new PointOld(3, 4));
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.