Test find object perfs

Benchmark created on


Setup

const generateRandomString = (len) => Math.random().toString(36).substring(2, len + 2);
  
const array = [];

for(let i = 0; i < 10000; i++) {
	const o = {
		id: generateRandomString(10),
		bbox: [0.47181372549019607, 0.5016339869281046, 0.0718954248366013, 0.08714596949891068],
		segmentation: [],
		image: "cyeQiUtiQ8KWMFojiy5KaA.jpg",
		area: 413562
	};
	
	array.push(o);
}

const map = array.reduce((acc, o) => ({...acc, [o.id]: o}), {});

const indexToRetrieve = parseInt(Math.random() * 10000);
const objectId = array[indexToRetrieve].id;

Test runner

Ready to run.

Testing in
TestOps/sec
Finding object by browsing an array
const found = array.find(o => o.id == objectId);
ready
Accessing object by key
const found = map[objectId];
ready

Revisions

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