Script Preparation code:
AخA
 
var oldData = { item1: 'olditem1', item2: 'olditem2', item3: 'unchanged' };
var newData = { item1: 'newitem1', item3: 'unchanged', item4: 'something else' };
Tests:
  • array push

     
    const result = [];
    Object.entries(oldData).forEach(([key, oldValue]) => {
      const newValue = newData[key];
      if (typeof newValue === 'undefined' || oldValue !== newValue) {
        result.push(key);
      }
    });
  • optimized push

     
    const result = [];
    Object.keys(oldData).forEach((key) => {
      if (oldData[key] !== newData[key]) {
        result.push(key);
      }
    });
  • reduce

    x
     
    const result = Object.entries(oldData).reduce((accum, [key, oldValue]) => {
      const newValue = newData[key];
      if (typeof newValue === 'undefined' || oldValue !== newValue) {
        return [...accum, key];
      }
      return accum;
    }, []);
  • optimized reduce

     
    const result = Object.keys(oldData).reduce((accum, key) => {
      if (oldData[key] !== newData[key]) {
        accum.push(key);
      }
      return accum;
    }, []);
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    array push
    optimized push
    reduce
    optimized reduce

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 17 days ago)
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36
Chrome 135 on Linux
View result in a separate tab
Test name Executions per second
array push 3729176.8 Ops/sec
optimized push 7997307.0 Ops/sec
reduce 6404052.0 Ops/sec
optimized reduce 7971214.5 Ops/sec