Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Class vs Function + Prototype
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36
Browser:
Chrome 130
Operating system:
Linux
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
Class
7.0 Ops/sec
Function + Prototype
9.1 Ops/sec
Script Preparation code:
class Iterator1 { array = Array.from({ length: 500_000 }, () => Math.floor(Math.random() * 500) + 1); iterate() { let sum = 0; for (let i = 0; i < this.array.length; ++i) sum += this.array[i]; } } const Iterator2 = function() {}; Iterator2.prototype.array = Array.from({ length: 500_000 }, () => Math.floor(Math.random() * 500) + 1); Iterator2.prototype.iterate = function() { let sum = 0; for (let i = 0; i < this.array.length; ++i) sum += this.array[i]; };
Tests:
Class
let iterator = new Iterator1(); for (let i = 0; i < 100; ++i) { iterator.iterate(); }
Function + Prototype
let iterator = new Iterator2(); for (let i = 0; i < 100; ++i) { iterator.iterate(); }