Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
ES6 Class vs Prototype vs Object Literal v2
Test the speed and memory usage using 3 different techniques for constructing class objects.
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36
Browser:
Chrome 139
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
8 months ago
Test name
Executions per second
ES6 Class
70027592.0 Ops/sec
Function Prototype
97943200.0 Ops/sec
Object Literal
1092325.6 Ops/sec
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); } function Point3(x, y) { return { x, y, add: (point) => Point3(this.x + point.x, this.y + point.y), sub: (point) => Point3(this.x - point.x, this.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 = Point3(10, 10); var p2 = Point3(10, -10); var sum = p1.add(p2); var dif = p1.sub(p2);