mapping vs find

Benchmark created on


Setup

const mapping = {};
const mapping2 = [];
const max = 20;

for (let i = 0; i < max; i++) {
	mapping['field_' + i] = {};
	for (let j = 0; j < max; j++) {
		mapping['field_' + i]['field_' + j] = ['some_config', String(i), String(j)]
		mapping2.push({
			key: 'field_' + i,
			key2: 'field_' + j,
			values: ['some_config', String(i), String(j)]
		})
	}
}

Test runner

Ready to run.

Testing in
TestOps/sec
mapping
const i = 'field_' + Math.floor(Math.random() * max);
const j = 'field_' + Math.floor(Math.random() * max);

const d = mapping[i][j];
ready
find
const i = 'field_' + Math.floor(Math.random() * max);
const j = 'field_' + Math.floor(Math.random() * max);

const d = mapping2.find(e => e.key === i && e.key2 === j).values;
ready

Revisions

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