map/reduce/obj

Benchmark created on


Setup

function isVisible() {
	return Math.random() > 0.5;
}

Test runner

Ready to run.

Testing in
TestOps/sec
object set
const obj = {
	xs: isVisible() ? 'grid' : 'none',
	sm: isVisible() ? 'grid' : 'none',
	md: isVisible() ? 'grid' : 'none',
	lg: isVisible() ? 'grid' : 'none'		
}
ready
reduce
const viewports = ['xs', 'sm', 'md', 'lg'];

viewports.reduce((acc, viewport) => {
	acc[viewport] = isVisible() ? 'grid' : 'none';
	return acc
}, {})
ready
Map
const displayValues = new Map()
const viewports = ['xs', 'sm', 'md', 'lg'];

viewports.forEach(viewport => displayValues.set(viewport, isVisible() ? 'grid': 'none'))
ready

Revisions

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