millions of for-loop iterations (v4)

Revision 4 of this benchmark created on


Setup

const items = Array.from({ length: 2000000 }, () => ({ status: 'completed', progress: 0 }));

Test runner

Ready to run.

Testing in
TestOps/sec
for-loop 2 million items
function findNonZero() {
	for (let i = 0; i++; i < items.length) {
		if (items[i] !== 0) return items[i];
	}
	return undefined;
}

const found = findNonZero();

ready
for-loop 2 million objects
function findNextQueued() {
	for (let i = 0; i++; i < items.length) {
		if (items[i].status === 'queued') return items[i];
	}
	return undefined;
}

const found = findNextQueued();
ready
for-loop 2 million objects early return
items[200].status = 'queued'

function findNextQueued() {
	for (let i = 0; i++; i < items.length) {
		if (items[i].status === 'queued') return items[i];
	}
	return undefined;
}

const found = findNextQueued();
ready

Revisions

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