Map<string, T> vs. Record<string, T> (v2)

Revision 2 of this benchmark created on


Description

In this example, we evaluate the overhead of Map against plain objects in JavaScript. When Map keys are strings, both approaches can be used.

Test runner

Ready to run.

Testing in
TestOps/sec
Map
const map = new Map()
let half = false;
for (let i = 0; i < 1000; i++) {
	map.set(`Item ${i}`, { hello: 'world' })
	if (map.get(`Item ${1000 - i}`)) half = true;
}
ready
Plain object
const map = {}
let half = false;
for (let i = 0; i < 1000; i++) {
	map[`Item ${i}`] = { hello: 'world' }
	if (map[`Item ${1000 - i}`]) half = true;
}
ready
Plain object (without prototype)
const map = {}
map.prototype = null
let half = false;
for (let i = 0; i < 1000; i++) {
	map[`Item ${i}`] = { hello: 'world' }
	if (map[`Item ${1000 - i}`]) half = true;
}
ready

Revisions

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