Object lookups with map vs record

Benchmark created on


Setup

const record = {};
const map = new Map();
const size = 1000;

new Array(size).fill(0).forEach((_, index) => {
	const key = `thing-${index}`;
	record[key] = key;
	map.set(key, key);
});

Test runner

Ready to run.

Testing in
TestOps/sec
Random lookup with Map
const keyIndex = Math.floor(Math.random() * size);
const value = map.get(`thing-${keyIndex}`);
ready
Random lookup with record
const keyIndex = Math.floor(Math.random() * size);
const value = record[`thing-${keyIndex}`];
ready

Revisions

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