Maximum

Benchmark created on


Setup

const a = Array(10_000).fill(0).map(() => Math.random());
const b = Array(10_000).fill(0).map(() => Math.random());
const c = Array(10_000).fill(0);

Test runner

Ready to run.

Testing in
TestOps/sec
if condition
for (let i = 0; i < c.length; i++) {
	if (a[i] > b[i]) c[i] = a[i];
	else c[i] = b[i];
}
ready
Math.max
for (let i = 0; i < c.length; i++) {
	c[i] = Math.max(a[i], b[i]);
}
ready
conditional select
for (let i = 0; i < c.length; i++) {
	const cond = a[i] > b[i];
	c[i] = cond * a[i] + (!cond) * b[i];
}
ready

Revisions

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