thenable vs promise (v3)

Revision 3 of this benchmark created on


Setup

function thenable(val, thenFn) {
  if (val instanceof Promise) {
    return val.then(thenFn)
  }

  return thenFn(val)
}

let i = 0;

Teardown

i = -1;

Test runner

Ready to run.

Testing in
TestOps/sec
mixed thenable
i += 1;

thenable(
	(i % 3) === 0
		? Promise.resolve(1)
		: 2,
	(val) => val * 2
)
ready
mixed Promise
i += 1;

Promise.resolve(
	(i % 3) === 0
		? Promise.resolve(1)
		: 2,
).then((val) => val * 2)
ready
sync thenable
i += 1;

thenable(
	(i % 3) === 0
		? 1
		: 2,
	(val) => val * 2
)
ready
sync Promise
i += 1;

Promise.resolve(
	(i % 3) === 0
		? 1
		: 2,
).then((val) => val * 2)
ready

Revisions

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