Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
ES6 Class vs Prototype vs Object Literal vs Object & Functions [rW@B8]
Test the speed and memory usage using 4 different techniques for constructing values and calling functions on them.
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:121.0) Gecko/20100101 Firefox/121.0
Browser:
Firefox 121
Operating system:
Windows
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
ES6 Class
891463.4 Ops/sec
Function Prototype
833396.6 Ops/sec
Object Literal
1348489.8 Ops/sec
Object & Functions
245927984.0 Ops/sec
Tests:
ES6 Class
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 p1 = new Point(10, 10); var p2 = new Point(10, -10); var sum = p1.add(p2); var dif = p1.sub(p2);
Function Prototype
function Point(x, y) { this.x = x; this.y = y; } Point.prototype.add = function(point) { return new Point(this.x + point.x, this.y + point.y); } Point.prototype.sub = function(point) { return new Point(this.x - point.x, this.y - point.y); } var p1 = new Point(10, 10); var p2 = new Point(10, -10); var sum = p1.add(p2); var dif = p1.sub(p2);
Object Literal
function Point(x, y) { return { x, y, add: (point)=>Point(this.x + point.x, this.y + point.y), sub: (point)=>Point(this.x - point.x, this.y - point.y) } } var p1 = Point(10, 10); var p2 = Point(10, -10); var sum = p1.add(p2); var dif = p1.sub(p2);
Object & Functions
function Point(x, y) { return { x, y, } } function add(a, b) { return Point(a.x + b.x, a.y + b.y); } function sub(a, b) { return Point(a.x - b.x, a.y - b.y); } var p1 = Point(10, 10); var p2 = Point(10, -10); var sum = add(p1, p2); var dif = sub(p1, p2);