Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
ES6 Class vs Prototype vs Object Literal vs Functional v3
(version: 1)
Comparing performance of:
ES6 Class vs Function Prototype vs Object Literal vs Functional
Created:
7 months ago
by:
Guest
Jump to the latest result
Script Preparation code:
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 Point1 = Point; function Point2(x, y) { this.x = x; this.y = y; } Point2.prototype.add = function(point) { return new Point2(this.x + point.x, this.y + point.y); } Point2.prototype.sub = function(point) { return new Point2(this.x - point.x, this.y - point.y); } var add3 = (point) => Point3(this.x + point.x, this.y + point.y) var sub3 = (point) => Point3(this.x - point.x, this.y - point.y) function Point3(x, y) { return { x, y, add: add3, sub: sub3 } } var add = (a, b) => (a.x + b.x, a.y + b.y) var sub = (a, b) => (a.x - b.x, a.y - b.y)
Tests:
ES6 Class
var p1 = new Point1(10, 10); var p2 = new Point1(10, -10); var sum = p1.add(p2); var dif = p1.sub(p2);
Function Prototype
var p1 = new Point2(10, 10); var p2 = new Point2(10, -10); var sum = p1.add(p2); var dif = p1.sub(p2);
Object Literal
var p1 = Point3(10, 10); var p2 = Point3(10, -10); var sum = p1.add(p2); var dif = p1.sub(p2);
Functional
var p1 = {x:10, y:10}; var p2 = {x:10, y:-10}; var sum = add(p1, p2); var dif = sub(p1, 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
Functional
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
5 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:145.0) Gecko/20100101 Firefox/145.0
Browser/OS:
Firefox 145 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
ES6 Class
18466430.0 Ops/sec
Function Prototype
17247944.0 Ops/sec
Object Literal
738414.1 Ops/sec
Functional
659719552.0 Ops/sec
Related benchmarks:
ES6 Class vs Prototype vs Object Literal v2
Instantiation via ES6 Class vs Prototype vs Object Literal
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 3
ES6 Class vs Prototype vs Object Literal v2 with Extends
ES6 Class vs Prototype vs Object Literal vs ES6 Class Extends
ES6 Class vs Prototype vs Object Literal v2 with Extends v3
ES6 Class vs Prototype vs Object Literal vs Functional v2
Comments
Confirm delete:
Do you really want to delete benchmark?