Looped promises vs promised loop (v2)

Revision 2 of this benchmark created on


Setup

// create an array with 2000 objects with some random data in them
const items = [];
for (let i = 0; i < 2000; i++) {
    items.push({
        id: i,
        name: 'name' + i,
        value: Math.random() * 100
    });
}
let total = 0
function doSomeHandling(item) {
	total += item.value;
}

Test runner

Ready to run.

Testing in
TestOps/sec
Looping through items calling async handler for each
async function handleData(item) {
	doSomeHandling(item);
}

async function receiveData(items) {
	for (const item of items) {
		await handleData(item);
	}
	deferred.resolve()
}

receiveData(items);
ready
Calling async handler that loops through items
async function handleData(items) {
	for (const item of items) {
		doSomeHandling
	}
}

async function receiveData(items) {
	await handleData(items);
	deferred.resolve()
}

receiveData(items);
ready

Revisions

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