Test name | Executions per second |
---|---|
Es6 Class | 1096965.1 Ops/sec |
Prototype | 1220574.6 Ops/sec |
Module | 82222896.0 Ops/sec |
class Es6Point {
constructor(x, y) {
this.x = x;
this.y = y;
}
add(point) {
return new Es6Point(this.x + point.x, this.y + point.y);
}
sub(point) {
return new Es6Point(this.x - point.x, this.y - point.y);
}
}
const p1 = new Es6Point(10, 10);
const p2 = new Es6Point(10, -10);
const sum = p1.add(p2);
const dif = p1.sub(p2);
function ProtoPoint(x, y) {
this.x = x;
this.y = y;
}
ProtoPoint.prototype.add = function(point) {
return new ProtoPoint(this.x + point.x, this.y + point.y);
}
ProtoPoint.prototype.sub = function(point) {
return new ProtoPoint(this.x - point.x, this.y - point.y);
}
const p1 = new ProtoPoint(10, 10);
const p2 = new ProtoPoint(10, -10);
const sum = p1.add(p2);
const dif = p1.sub(p2);
const ModulePoint = (x, y) => ({
add: point => ModulePoint(x + point.x, y + point.y),
sub: point => ModulePoint(x - point.x, y - point.y)
})
const p1 = ModulePoint(10, 10)
const p2 = ModulePoint(10, -10)
const sum = p1.add(p2)
const dif = p1.sub(p2)