MapVsObjLookup (v3)

Revision 3 of this benchmark created on


Description

Test performance of finding and accessing a key of a map, or the property of an object.

Preparation HTML


Setup

let obj = {}

let map = new Map()

for (let i = 1; i <= 100; i++){
  obj[`/${i}/${i*10}/${i*100}`] = '/value/does/not/matter'
  map.set(`/${i}/${i*10}/${i*100}`,'/value/does/not/matter'
  )
}


Test runner

Ready to run.

Testing in
TestOps/sec
index of object key
let objTests = ["/foo", "/a/b/c", "/bar", "/baz"];
let objKeys = Object.keys(obj);
objTests.forEach((path) => objKeys.indexOf(path)) >= -1;
ready
map has
let mapTests = ["/foo", "/a/b/c", "/bar", "/baz"];
mapTests.forEach((path) => map.has(path));
ready
property in object
let objTests = ["/foo", "/a/b/c", "/bar", "/baz"];
objTests.forEach((path) => path in obj)

ready
object has own property
let objTests = ["/foo", "/a/b/c", "/bar", "/baz"];
objTests.forEach((path) => Object.hasOwn(obj, path))

ready

Revisions

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