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 (X11; Linux x86_64; rv:134.0) Gecko/20100101 Firefox/134.0
Browser:
Firefox 134
Operating system:
Linux
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
class
10479.2 Ops/sec
closure
12321.3 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()