Script Preparation code:
x
 
var data = { ...Array.from(Array(10000).keys()) };
const filterWithObject = (val) => {
  const result = {}
  for (const key in val) {
    if (Number(key) % 2 === 0) {
      continue;
    }
    result[key] = val[key];
  } 
  return result;
};
const filterWithMap = (val) => {
  const result = new Map();
  for (const key in val) {
    if (Number(key) % 2 === 0) {
      continue;
    }
    result.set(key, val[key]);
  } 
  return Object.fromEntries(result.entries());
};
Tests:
  • Reduce (object)

     
    Object.keys(data)
            .filter(key => Number(key) % 2 === 0)
            .reduce((acc, key) => {
              acc[key] = data[key];
              return acc;
            }, {});
  • Reduce (Map)

     
    Object.keys(data)
            .filter(key => Number(key) % 2 === 0)
            .reduce((acc, key) => {
              acc.set(key, data[key]);
              return acc;
            }, new Map());
  • for-of (object)

     
    filterWithObject(data)
  • for-of (Map)

     
    filterWithMap(data)
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Reduce (object)
    Reduce (Map)
    for-of (object)
    for-of (Map)

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 26 days ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36 Edg/134.0.0.0
Chrome 134 on Windows
View result in a separate tab
Test name Executions per second
Reduce (object) 4154.3 Ops/sec
Reduce (Map) 2769.7 Ops/sec
for-of (object) 4238.5 Ops/sec
for-of (Map) 1310.7 Ops/sec