High read object lookup

Benchmark created on


Setup

const keyPrefix = 'someveryveryveryverylongkeyname_';
const totalItems = 10000;
const totalUndefinedItems = 100000;
const totalReadTimes = totalItems / 5;
const map = {};
const mapWithUndefined = {};

function setupMap() {
	for (let i = 1; i <= totalItems; i++) {
		map[keyPrefix + (totalItems + i)] = { foo: 'bar'};
		mapWithUndefined[keyPrefix + (totalItems + i)] = { foo: 'bar'};
	}
	
	for (let i = 1; i <= totalUndefinedItems; i++) {
		mapWithUndefined[keyPrefix + (totalItems * 2 + i)] = undefined;
	}
}

function loopRead(lookup) {
	const step = totalItems / totalReadTimes;
	
	for (let i = 1; i <= totalReadTimes; i++) {
		lookup[keyPrefix + (totalItems + Math.floor(step * i))] === undefined;
	}
}

setupMap();

Test runner

Ready to run.

Testing in
TestOps/sec
Read normal map
loopRead(map)
ready
Read map with huge undefined keys
loopRead(mapWithUndefined)
ready

Revisions

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