Array vs Map

Benchmark created on


Setup

const testObj = {id: 123};

const arr = Array(10000).fill(true).map(() => ({id: Math.floor(Math.random() * 100000)}))
const map = new Map();
arr.forEach(obj => map.set(obj.id, obj))

const arrWorst = [...arr, testObj]
const arrBest = [testObj, ...arr]
map.set(testObj.id, testObj);

Test runner

Ready to run.

Testing in
TestOps/sec
Array of 10k users, worst case
arrWorst.find(obj => obj.id === testObj.id)
ready
Array of 10k users, best case
arrBest.find(obj => obj.id === testObj.id)
ready
Map of 10k users
map.get(testObj.id)
ready

Revisions

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