Generator performance

Benchmark created on


Setup

function* generator(n) {
	for (let i=0; i<n; i++) {
		yield i;
	}
}
function generatorCb(n, cb) {
	for (let i=0; i<n; i++) {
		cb(i);
	}
}

Test runner

Ready to run.

Testing in
TestOps/sec
plain for loop
let s = 0;
for (let i=0; i<100; i++) {
	s += i*i;
}
ready
generator
let s = 0;
for (const i of generator(100)) {
	s += i*i;
}
ready
callback
let s = 0;
generatorCb(100, (i) => {
	s += i*i;
})
ready

Revisions

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