Object vs Map

Benchmark created on


Setup

const iterations = 100000;

const obj = {};

for (let i = 0; i < iterations; i++) {
	const id = String(i);
	obj[id] = { id: id, [id]: id };
}

const map = new Map;

for (let i = 0; i < iterations; i++) {
	const id = String(i);
	map.set(id, { id: id, [id]: id });
}

Test runner

Ready to run.

Testing in
TestOps/sec
Object
for (let i = 0; i < iterations; i++) {
	let a = obj[String(i)];
}
ready
Map
for (let i = 0; i < iterations; i++) {
	let a = map.get(String(i));
}
ready

Revisions

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