mapping

Benchmark created on


Setup

function getRandomString(length) {
  const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
  let result = '';
  const charactersLength = characters.length;
  for (let i = 0; i < length; i++) {
    result += characters.charAt(Math.floor(Math.random() * charactersLength));
  }
  return result;
}

function getRandomKeyValuePair() {
  const key = getRandomString(5); // Random key of length 5
  const value = getRandomString(8); // Random value of length 8
  return [key,value]
}

const arrayOfObjects = Array.from({ length: 10 }, getRandomKeyValuePair);


Test runner

Ready to run.

Testing in
TestOps/sec
reverse array
const ary =arrayOfObjects.slice().reverse()
const m = new Map(ary)
ready
manual
const s = new Map()
for (const item of arrayOfObjects) {
	if(!s.has(item[0])){s.set(item[0],item[1])}
}
ready
today
const m = new Map(arrayOfObjects)
ready
toReversed
const m = new Map(arrayOfObjects.toReversed())
ready

Revisions

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