Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Instantiation via ES6 Class vs Prototype vs Object Literal
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/145.0.0.0 Safari/537.36
Browser:
Chrome 145
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
13 days ago
Test name
Executions per second
ES6 Class
21543.6 Ops/sec
Function Prototype
14680.2 Ops/sec
Object Literal
6764.5 Ops/sec
Script Preparation code:
class PointClass { constructor(x, y){ this.x = x; this.y = y; } add(point){ return new PointClass(this.x + point.x, this.y + point.y); } sub(point){ return new PointClass(this.x - point.x, this.y - point.y); } } function PointProto(x, y){ this.x = x; this.y = y; } PointProto.prototype.add = function(point){ return new PointProto(this.x + point.x, this.y + point.y); } PointProto.prototype.sub = function(point){ return new PointProto(this.x - point.x, this.y - point.y); } function PointFactory(x, y){ return { x, y, add: (point)=>PointFactory(this.x + point.x, this.y + point.y), sub: (point)=>PointFactory(this.x - point.x, this.y - point.y) } } window.PointClass = PointClass window.PointProto = PointProto window.PointFactory = PointFactory window.num = 10_000
Tests:
ES6 Class
const points = [] for (let index = 0; index < num; index++) { points.push(new PointClass(10, 10)) }
Function Prototype
const points = [] for (let index = 0; index < num; index++) { points.push(new PointProto(10, 10)) }
Object Literal
const points = [] for (let index = 0; index < num; index++) { points.push(PointFactory(10, 10)) }