Map vs Object (Large) (v5)

Revision 5 of this benchmark created on


Description

Compares performance of a map vs an object.

In both cases, the map and object are largs, with large amounts of properties added to them. This simulates an object that might be used as a lookup table.

Setup

function createLargeObject() {
	let OBJ = { "string": 1 };
	for(let i = 0; i < 4; i++) {
		for(let j = 0; j < 200; j++) {
			let R = (Math.random() * 100).toString();
			OBJ[R] = R;
		}
	}
	return OBJ;
}

function createLargeConstObject() {
	let OBJ = { "string": 1 };
	for(let i = 0; i < 4; i++) {
		for(let j = 0; j < 200; j++) {
			let R = (Math.random() * 100).toString();
			OBJ[R] = R;
		}
	}
	return {...OBJ};
}

function createLargeMap() {
	let MAP = new Map([["string", 1]]);
	for(let i = 0; i < 4; i++) {
		for(let j = 0; j < 200; j++) {
			let R = (Math.random() * 100).toString();
			MAP.set(R, R);
		}
	}
	return MAP;
}

var OBJ = createLargeObject();
var MAP = createLargeMap();
var CONSTOBJ = createLargeConstObject();
var RESULT;

Test runner

Ready to run.

Testing in
TestOps/sec
Get (Object)
RESULT = OBJ["string"];
ready
Get (Map)
RESULT = MAP.get("string");
ready
Get (ConstObject)
RESULT = CONSTOBJ["string"];
ready

Revisions

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