Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
ES6 Class vs Prototype vs Object Literal v2 with Extends v2
(version: 1)
Test the speed and memory usage using 3 different techniques for constructing class objects.
Comparing performance of:
ES6 Class vs Function Prototype vs Object Literal
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
class BaseClass { constructor() {} } class Point extends BaseClass { constructor(x, y) { super(); 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 BaseConstructor() {} 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); } Object.setPrototypeOf(Object.setPrototypeOf(Point2, BaseConstructor).prototype, BaseConstructor.prototype); function PointX(x, y) { return {} } function Point3(x, y) { return { ...PointX(x, y), x, y, add: (point) => Point3(x + point.x, y + point.y), sub: (point) => Point3(x - point.x, y - point.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 = new Point3(10, 10); var p2 = new Point3(10, -10); var sum = p1.add(p2); var dif = p1.sub(p2);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
ES6 Class
Function Prototype
Object Literal
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36
Browser/OS:
Chrome 133 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
ES6 Class
90181184.0 Ops/sec
Function Prototype
129690208.0 Ops/sec
Object Literal
14034221.0 Ops/sec
Related benchmarks:
ES6 Class vs Prototype vs Object Literal v2
Instantiation via ES6 Class vs Prototype vs Object Literal
ES6 Class vs Prototype vs Object Literal 2
ES6 Class vs Prototype vs Object Literal 3
Comparison of classes vs prototypes vs object literals also including the inheritance
ES6 Class vs Prototype vs Object Literal v2 with Extends
ES6 Class vs Prototype vs Object Literal vs ES6 Class extends vs ES6 Class extends twice
ES6 Class vs Prototype vs Object Literal vs ES6 Class Extends
ES6 Class vs Prototype vs Object Literal v2 with Extends v3
Comments
Confirm delete:
Do you really want to delete benchmark?