Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36
Chrome 73
Windows
Desktop
5 years ago
Test name Executions per second
getOwnPropertyNames 3170017.8 Ops/sec
for ... in 7081667.5 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++;
    }