await vs then (v9)

Revision 9 of this benchmark created on


Setup

const promise = () => new Promise((resolve) => {
	setTimeout(() => {resolve('done')}, 5); 
});

Test runner

Ready to run.

Testing in
TestOps/sec
await
const exec = async () => {
	const result = await promise();

	console.log('after await', result);
}

exec();

console.log('immediately');
ready
then
const exec = () => {
	const result = promise();
	
	result.then((result) => {
		console.log('after then', result);	
	})
}

exec();

console.log('immediately');
ready

Revisions

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