Async await vs sync call

Benchmark created on


Setup

async function addOneP(a, b) {
	return a + b
}

function addOneS(a, b) {
	return a + b
}

Test runner

Ready to run.

Testing in
TestOps/sec
Sync
function doit() {
	let sum = 0;
	for (let i = 0; i < 1_000_000; ++i) {
		sum = addOneS(sum, i);
	}
	return sum;
}

const sum = doit();
console.log("sum", sum);
ready
Async
async function doit() {
	let sum = 0;
	for (let i = 0; i < 1_000_000; ++i) {
		sum = await addOneP(sum, i);
	}
	return sum;
}

const sum = await doit();
console.log("sum", sum);
ready
Sync in P
async function doit() {
	let sum = 0;
	for (let i = 0; i < 1_000_000; ++i) {
		sum = addOneS(sum, i);
	}
	return sum;
}

const sum = await doit();
console.log("sum", sum);
ready

Revisions

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