Array vs Object lookup

Benchmark created on


Description

The goal is to find out if operating on an array of objects with a key property is faster or slower than looking up a key from an object.

Setup

const storageArr = [];
const storageObj = {}
for (let i = 0; i < 10000; i += 1) {
	storageArr.push({ key: String(i), value: i });
	storageObj[String[i]] = i;
}

Test runner

Ready to run.

Testing in
TestOps/sec
Look up first item in array
const item = storageArr.find(i => i.key === "0")
ready
Look up last item in array
const item = storageArr.find(i => i.key === "9999")
ready
Look up first item in object
const item = storageObj["0"]
ready
Look up last item in object
const item = storageObj["9999"]
ready

Revisions

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