Class vs Higher order function

Benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
Class
class Counter {
	count = 0;
	increment(){
		this.count++;
	}
	getValue(){
		return this.count;
	}
}
const counter = new Counter();
counter.increment();
counter.getValue();
ready
Function
function createCounter() {
	let count = 0;
	return {
		increment: () => {
			count = count + 1;
		},
		getValue: () => count
	}
}
const counter = createCounter();
counter.increment();
counter.getValue();
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.