Script Preparation code:
AخA
 
var data = { ...Array.from(Array(10000).keys()) };
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)

    x
     
    const filter = (val) => {
      const result = {}
      for (const key in val) {
        if (Number(key) % 2 === 0) {
          continue;
        }
        result[key] = val[key];
      } 
      return result;
    };
  • for-of (Map)

     
    const filter = (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());
    };
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; rv:136.0) Gecko/20100101 Firefox/136.0
Firefox 136 on Windows
View result in a separate tab
Test name Executions per second
Reduce (object) 2439.2 Ops/sec
Reduce (Map) 1638.2 Ops/sec
for-of (object) 1851825536.0 Ops/sec
for-of (Map) 1862645120.0 Ops/sec