Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
Feature Requests
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
Benchmark engine:
Benchmark.js
closure
12K/s
class
10K/s
View exact numbers
Test name
Executions per second
✓
closure
12,321 Ops/sec
class
10,479 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()