Lookups

Benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
Object
const colors = {
	blue: 'blue',
	red: 'red',
	green: 'green',
	yellow: 'yellow'
}
const getColor = (key) => colors[key] || 'yellow';

getColor('red')
ready
If
const colors = {
	blue: 'blue',
	red: 'red',
	green: 'green',
	yellow: 'yellow'
}
const getColor = (key) => {
	if (key === 'blue') return 'blue';
	if (key === 'red') return 'red';
	if (key === 'green') return 'green';
	if (key === 'yellow') return 'yellow';
	return 'yellow'
}

getColor('red')
ready

Revisions

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