Script Preparation code:
x
 
var obj = {};
var count = 10;
do {
    obj["key" + count + ""] = "val" + count + "";
} while(count--);
var temp = [];
for(var key in obj) {
   temp.push(obj[key]);
}
var objKey = [];
var keys = Object.keys(obj);
for(var i = 0, len = keys.length; i < len; i++) {
   objKey.push(obj[keys[i]]);
}
Tests:
  • for (key in obj)

     
    var temp = [];
    for(var key in obj) {
       temp.push(obj[key]);
    }
  • Object.keys(obj)

     
    var objKey = [];
    var keys = Object.keys(obj);
    for(var i = 0, len = keys.length; i < len; i++) {
       objKey.push(obj[keys[i]]);
    }
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    for (key in obj)
    Object.keys(obj)

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 2 months ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36
Chrome 130 on Windows
View result in a separate tab
Test name Executions per second
for (key in obj) 851649.8 Ops/sec
Object.keys(obj) 694870.4 Ops/sec