Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.5 Safari/605.1.15
Safari 16
Mac OS X 10.15.7
Desktop
one year ago
Test name Executions per second
Object.entries 188589.3 Ops/sec
Object.keys 448811.9 Ops/sec
Object.values 840091.8 Ops/sec
Script Preparation code:
x
 
function makeid() {
  var text = "";
  var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  for (var i = 0; i < 5; i++)
    text += possible.charAt(Math.floor(Math.random() * possible.length));
  return text;
}
window.parentObj = {};
for (let i = 0; i < 100; i++) {
    window.parentObj[makeid()] = { innerVal: makeid() };
}
Tests:
  • Object.entries

     
    const newObj = {};
    newObj.count = Object.entries(window.parentObj).length;
  • Object.keys

     
    const newObj = {};
    newObj.count = Object.keys(window.parentObj).length;
  • Object.values

     
    const newObj = {};
    newObj.count = Object.values(window.parentObj).length;