Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 Safari/537.36
Chrome 91
Mac OS X 10.15.7
Desktop
3 years ago
Test name Executions per second
hasOwnProperty 131424.3 Ops/sec
Object.keys 422004.7 Ops/sec
Script Preparation code:
AخA
 
var props = {a:1,b:1,c:1,d:1,e:1,f:1,g:1,h:1,i:1,j:1,k:1,l:1,m:1,n:1,o:1,p:1,q:1,r:1,s:1,t:1,u:1,v:1,w:1,x:1,y:1,z:1};
Tests:
  • hasOwnProperty

     
    for (var p in props) {
      if (Object.prototype.hasOwnProperty.call(props, p)) {
        props[p] = 2;
      }
    }
  • Object.keys

     
    for (var k=Object.keys(props), l=k.length, i=0; i<l; i++) {
      props[k[i]] = 2;
    }