reduce/merge vs object set

Benchmark created on


Setup

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

Test runner

Ready to run.

Testing in
TestOps/sec
reduce/merge
const viewports = ['xs', 'sm', 'md', 'lg'];

viewports.reduce((acc, viewport) => {
	return {
		...acc,
		[viewport]: isVisible() ? 'grid' : 'none'
	}
}, {})
ready
object set
const obj = {
	xs: isVisible() ? 'grid' : 'none',
	sm: isVisible() ? 'grid' : 'none',
	md: isVisible() ? 'grid' : 'none',
	lg: isVisible() ? 'grid' : 'none'		
}
ready

Revisions

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