MapVsObjRedirectLookup

Benchmark created on


Description

Test performance of finding and accessing a url in a list of redirect urls.

Preparation HTML


Setup

let objRedirects = {
  '/foo': '/bar',
  '/a/b/c': '/d/e/f',
  '/xxxxx': '/xxxxx'
}

let mappedRedirects = new Map([
  ['/foo', '/bar'],
  ['/a/b/c', '/d/e/f'],
  ['/xxxxx', '/xxxxx']
])

for (let i = 1; i <= 100; i++){
  objRedirects[`/${i}/${i}/${i}`] = '/value/does/not/matter'
  mappedRedirects.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(objRedirects);
objTests.forEach((path) => objKeys.indexOf(path)) >= -1;
ready
map has
let mapTests = ["/foo", "/a/b/c", "/bar", "/baz"];
mapTests.forEach((path) => mappedRedirects.has(path));
ready
property in object
let objTests = ["/foo", "/a/b/c", "/bar", "/baz"];
objTests.forEach((path) => path in objRedirects)

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

ready

Revisions

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