Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Class vs Function + Prototype
(version: 1)
Comparing performance of:
Class vs Function + Prototype
Created:
one year ago
by:
Guest
Jump to the latest result
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(); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Class
Function + Prototype
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36
Browser/OS:
Chrome 130 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Class
17.2 Ops/sec
Function + Prototype
27.7 Ops/sec
Related benchmarks:
Fat Arrow
Qqqqqq
Qqqqqqqq
Qqqqqqqqq
"this" dereference
Test prototype speed
Test prototype speed
For Each comparison
test124578
Comments
Confirm delete:
Do you really want to delete benchmark?