Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
ES6 Class vs Prototype vs Object Literal vs ES6 Class Extends
(version: 1)
Comparing performance of:
ES6 Class vs Function Prototype vs Object Literal vs Class extends
Created:
one year ago
by:
Registered User
Jump to the latest result
Script Preparation code:
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 } }
Tests:
ES6 Class
var p1 = new ClassPoint(10, 10); var p2 = new ClassPoint(10, -10); var sum = p1.add(p2); var dif = p1.sub(p2);
Function Prototype
var p1 = new FunctionPoint(10, 10); var p2 = new FunctionPoint(10, -10); var sum = p1.add(p2); var dif = p1.sub(p2);
Object Literal
var p1 = ObjectPoint(10, 10); var p2 = ObjectPoint(10, -10); var sum = p1.add(p2); var dif = p1.sub(p2);
Class extends
var p1 = new ClassPoint2(10, 10); var p2 = new ClassPoint2(10, -10); var sum = p1.add(p2); var dif = p1.sub(p2);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
ES6 Class
Function Prototype
Object Literal
Class extends
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
4 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:146.0) Gecko/20100101 Firefox/146.0
Browser/OS:
Firefox 146 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
ES6 Class
29775672.0 Ops/sec
Function Prototype
23300102.0 Ops/sec
Object Literal
1057811.1 Ops/sec
Class extends
21164500.0 Ops/sec
Related benchmarks:
ES6 Class vs Prototype vs Object Literal v2
Instantiation via ES6 Class vs Prototype vs Object Literal
es6 vs prototype class
Long and dynamic Inheritance => Prototype vs Object Literal - v1
Long and dynamic Inheritance => Prototype vs Object Literal - v2
ES6 Class vs Prototype vs Object Literal v2 with Extends
ES6 Class vs Prototype vs Object Literal vs Function vs Function with object destructuring
ES6 Class vs Prototype vs Object Literal v3
ES6 Class vs Prototype vs Object Literal vs ES6 Class extends vs ES6 Class extends twice
Comments
Confirm delete:
Do you really want to delete benchmark?