HTML Preparation code:
x
 
1
2
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
 
var obj = {
  a: 1,
  b: 2,
  c: 3,
}
Tests:
  • lodash forOwn

     
    _.forOwn(obj, (a) => {console.log(a)});
  • Keys and then forEach

     
    Object.keys(obj).forEach((a) => {console.log(a)});
  • for key

     
    for (let key in obj) {
        // check if the property/key is defined in the object itself, not in parent
        if (obj.hasOwnProperty(key)) {           
            console.log(key, obj[key]);
        }
    }
  • for key value

     
    for (const [key, value] of Object.entries(obj)) {
      console.log(key, value);
    }
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    lodash forOwn
    Keys and then forEach
    for key
    for key value

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 2 years ago)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36
Chrome 110 on Mac OS X 10.15.7
View result in a separate tab
Test name Executions per second
lodash forOwn 56064.3 Ops/sec
Keys and then forEach 72947.8 Ops/sec
for key 63480.6 Ops/sec
for key value 65181.1 Ops/sec