Test name | Executions per second |
---|---|
ES6 Class | 80367560.0 Ops/sec |
Function Prototype | 86437768.0 Ops/sec |
Object Literal | 9827788.0 Ops/sec |
Class extends | 55557320.0 Ops/sec |
class ClassPoint {
constructor(x, y) {
this.x = x;
this.y = y;
}
add(point) {
this.x = this.x + point.x
this.y = this.y + point.y
}
sub(point) {
this.x = this.x - point.x
this.y = this.y - point.y
}
}
function FunctionPoint(x, y){
this.x = x;
this.y = y;
}
FunctionPoint.prototype.add = function(point){
this.x = this.x + point.x
this.y = this.y + point.y
}
FunctionPoint.prototype.sub = function(point){
this.x = this.x - point.x
this.y = this.y - point.y
}
function ObjectPoint(x, y){
return {
x,
y,
add:(point) => {
this.x = this.x + point.x
this.y = this.y + point.y
},
sub:(point) => {
this.x = this.x - point.x
this.y = this.y - point.y
},
}
}
class Base {
constructor(x, y){
this.x = x;
this.y = y;
}
}
class ClassPoint2 extends Base {
add(point){
this.x = this.x + point.x
this.y = this.y + point.y
}
sub(point){
this.x = this.x - point.x
this.y = this.y - point.y
}
}
var p1 = new ClassPoint(10, 10);
var p2 = new ClassPoint(10, -10);
var sum = p1.add(p2);
var dif = p1.sub(p2);
var p1 = new FunctionPoint(10, 10);
var p2 = new FunctionPoint(10, -10);
var sum = p1.add(p2);
var dif = p1.sub(p2);
var p1 = ObjectPoint(10, 10);
var p2 = ObjectPoint(10, -10);
var sum = p1.add(p2);
var dif = p1.sub(p2);
var p1 = new ClassPoint2(10, 10);
var p2 = new ClassPoint2(10, -10);
var sum = p1.add(p2);
var dif = p1.sub(p2);