Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
closure vs classes js
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36
Browser:
Chrome 129
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
closures
602.8 Ops/sec
classes
579.1 Ops/sec
Tests:
closures
function createClosure(one, two) { let result = null; return { compute() { result = one * two * one * two; }, printResult() { console.log(result) } } } const amt = 200; let contents = new Array(amt); for (let i = 0; i < amt; i ++) { contents[i] = createClosure(Math.random(), Math.random()); contents[i].compute(); contents[i].printResult(); }
classes
class MyClass { result = null; constructor(one, two) { this.one = one; this.two = two; } compute() { this.result = this.one * this.two * this.one * this.two; } printResult() { console.log(this.result); } } const amt = 200; let contents = new Array(amt); for (let i = 0; i < amt; i ++) { contents[i] = new MyClass(Math.random(), Math.random()); contents[i].compute(); contents[i].printResult(); }