Conditional branches

Benchmark created on


Description

Test conditional branch

Setup

function f0(order) {
	if (order < 0) return 'desc'
	return 'asc'
}

function f1(order) {
	return order < 0 ? 'desc' : 'asc'
}

const m2 = [
	'desc',
	'asc',
	'asc'
]

function f2(order) {
	return m2[order + 1]
}

Test runner

Ready to run.

Testing in
TestOps/sec
Function 0 (use conditional branch, long)
f0(-1)
f0(1)
f0(0)
f0(1)
f0(0)
f0(-1)
ready
Function 1 (use conditional branch, short)
f1(-1)
f1(1)
f1(0)
f1(1)
f1(0)
f1(-1)
ready
Function 2 (use map)
f2(-1)
f2(1)
f2(0)
f2(1)
f2(0)
f2(-1)
ready

Revisions

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