Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
javascript class vs function closure
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (iPhone; CPU iPhone OS 18_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.0.1 Mobile/15E148 Safari/604.1
Browser:
Mobile Safari 26
Operating system:
iOS 18.7
Device Platform:
Mobile
Date tested:
7 months ago
Test name
Executions per second
class
126475.7 Ops/sec
closure
127105.0 Ops/sec
Tests:
class
class CowClass { constructor(lungCapacity) { this.lungCapacity = lungCapacity this.airInLungs = 0 } getAirInLungs() { return this.airInLungs } breathe () { this.airInLungs = this.lungCapacity } moo () { let output = 'm' let air = this.getAirInLungs() while (air --> 0) { // The 'goes to' operator output += 'o' } this.airInLungs = air return output } } const cow = new CowClass(3000) cow.breathe() cow.moo()
closure
function CowClosure(lungCapacity) { let airInLungs = 0 function breathe () { airInLungs = lungCapacity } function getAirInLungs () { return airInLungs } function moo () { let output = 'm' let air = getAirInLungs() while (air --> 0) { // The 'goes to' operator.df output += 'o' } airInLungs = air return output } return {breathe:breathe, moo:moo} } const cow = CowClosure(3000) cow.breathe() cow.moo()