Simple generator vs custom iterator (v2)

Revision 2 of this benchmark created on


Setup

const arr = Array.from({ length: 10_000 }).map((_, i) => i)

Test runner

Ready to run.

Testing in
TestOps/sec
Iteratable
const elems = {
	[Symbol.iterator]() {
		let i = 0
		return {
			next: () => ({ value: arr[i], done: i++ >= arr.length})
		}
	}
};

[...elems]
ready
Generator
function* fn() {
	for (let i = 0; i < arr.length; i++) {
		yield arr[i]
	}
};

[...fn()]
ready

Revisions

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