Run details:
Mozilla/5.0 (X11; Linux x86_64; rv:81.0) Gecko/20100101 Firefox/81.0
Firefox 81
Linux
Desktop
4 years ago
Test name Executions per second
getOwnPropertyNames 5192009.0 Ops/sec
for ... in 23440722.0 Ops/sec
Script Preparation code:
AخA
 
var obj = {
  $props : ['a','b','c'],
  a:1,
  b:2,
  c:3
}
Tests:
  • getOwnPropertyNames

     
    const arr = Object.keys(obj);
    let n = 0;
    for (let i = 0; i < arr.length; i++) {
      const k = arr[i];
      if (k.charAt(0) == '$') continue;
      n++;
    }
  • for ... in

     
    let n = 0;
    for (const k in obj) {
      if (k.charAt(0) == '$') continue;
      n++;
    }