Script Preparation code:
AخA
 
function getObj(i) {
  return {
    'a': {
      id: 'a',
      num: 1
    },
    'b': {
      id: 'b',
      num: 1
    },
    'c': {
      id: 'c',
      num: 1
    },
    'd': {
      id: 'd',
      num: 1
    },
    'e': {
      id: 'e',
      num: 1
    },
    'f': {
      id: 'f',
      num: 1
    },
    'g': {
      id: 'g',
      num: 1
    },
    [i.toString()]: 1,
  };
};
Tests:
  • for-in

     
    const r = [];
    for (var i=10000; i > 0; i--) {
      for (var key in getObj(i)) {
          r[i] = key;
      }
    }
    console.log(r.length)
  • Object.keys

     
    const r = [];
    for (var i=10000; i > 0; i--) {
      Object.keys(getObj(i)).forEach(key => { r[i] = key; });
    }
    console.log(r.length)
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    for-in
    Object.keys

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: one month ago)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36
Chrome 133 on Mac OS X 10.15.7
View result in a separate tab
Test name Executions per second
for-in 252.4 Ops/sec
Object.keys 318.1 Ops/sec