Script Preparation code:
AخA
 
var obj = {
  'a': 1,
  'b': 1,
  'c': 1,
  'd': 1,
  'e': 1,
  'f': 1,
  'g': 1
};
Tests:
  • for-in

     
    for (var i=10000; i > 0; i--) {
      for (var key in obj) {
          console.log(key); 
      }
    }
  • Object.keys forEach

     
    for (var i=10000; i > 0; i--) {
      Object.keys(obj).forEach(key => console.log(key));
    }
  • Object.keys for loop

     
    for (var i=10000; i > 0; i--) {
      const keys = Object.keys(obj);
      for (let i = 0; i < keys.length; i++) {
        console.log(obj[keys[i]]);
      }
    }
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    for-in
    Object.keys forEach
    Object.keys for loop

    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/133.0.0.0 Safari/537.36
Chrome 133 on Windows
View result in a separate tab
Test name Executions per second
for-in 6.7 Ops/sec
Object.keys forEach 5.4 Ops/sec
Object.keys for loop 6.5 Ops/sec