Map

Benchmark created on


Setup

const arr = [{a: 1, b: 2, c: 3, d: 0}, {a: 1, b: 2, c: 3, d: 1}, {a: 1, b: 2, c: 3, d: 2}, {a: 1, b: 2, c: 3, d: 3}, {a: 1, b: 2, c: 3, d: 4}, {a: 1, b: 2, c: 3, d: 5}, {a: 1, b: 2, c: 3, d: 6}, {a: 1, b: 2, c: 3, d: 7}, {a: 1, b: 2, c: 3, d: 8}, {a: 1, b: 2, c: 3, d: 9}, {a: 1, b: 2, c: 3, d: 10}]

Test runner

Ready to run.

Testing in
TestOps/sec
constructor
const map = new Map(arr.map(i => [i.d, i]))
ready
for-loop
const map = new Map()

for (const i of arr) {
	map.set(i.d, i)
}
ready
for-each
const map = new Map()

arr.forEach(i => map.set(i.d, i))
ready

Revisions

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