Script Preparation code:
x
 
function setup() {
  const randInt = (min, max) =>
      Math.floor(Math.random() * (max - min + 1) + min);
  const itemMap = {};
  const itemArr = [];
  for (let i = 0; i < 10000; i++) {
      const item = {
          id: randInt(0, 1000000),
          value: `value-${randInt(0, 1000000)}`
      };
      itemArr.push(item);
      itemMap[item.id] = item;
  }
  const itemIdsToGet = [itemArr[8002].id, itemArr[2423].id, itemArr[5322].id, itemArr[3].id, itemArr[7242].id]
  
  return {
    itemIdsToGet,
    itemMap,
    itemArr
  }
}
Tests:
  • map

     
    const values = setup();
    for  (const itemIdToUpdate of values.itemIdsToGet) {
      values.itemMap[itemIdToUpdate].value = 'updated'
    }
  • array

     
    const values = setup();
    for  (const itemIdToUpdate of values.itemIdsToGet) {
      const index = values.itemArr.findIndex(x => x.id === itemIdToUpdate);
      
      values.itemArr[index].value = 'updated';
    }
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    map
    array

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 3 years ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36
Chrome 97 on Windows
View result in a separate tab
Test name Executions per second
map 177.5 Ops/sec
array 182.3 Ops/sec