Array.includes vs Object member lookup

Benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
Object member lookup
const cellMap = new Map()
cellMap.set('1', 0)
cellMap.set('2', 1)
cellMap.set('3', 2)
cellMap.set('4', 3)

const cells = [
	{
		cellKey: null,
	},
	{
		cellKey: null,
	},
	{
		cellKey: null,
	},
	{
		cellKey: null,
	},
]

const freeCells = [0,1,2,3]

const cellPoolIndex = cellMap.get('2')
const isCellActive = (cellPoolIndex != null ? cells[cellPoolIndex].cellKey : null) != null
ready
Array.includes
const cellMap = new Map()
cellMap.set('1', 0)
cellMap.set('2', 1)
cellMap.set('3', 2)
cellMap.set('4', 3)

const cells = [
	{
		cellKey: null,
	},
	{
		cellKey: null,
	},
	{
		cellKey: null,
	},
	{
		cellKey: null,
	},
]

const freeCells = [0,1,2,3]

const cellPoolIndex = cellMap.get('2')
const isCellActive = !freeCells.includes(cellPoolIndex)
ready

Revisions

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