Run details:
Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:137.0) Gecko/20100101 Firefox/137.0
Firefox 137
Ubuntu
Desktop
one month ago
Test name Executions per second
Object.hasOwn 4854.9 Ops/sec
Set.prototype.has 4503.9 Ops/sec
Script Preparation code:
AخA
 
window.myObject = {};
window.mySet = new Set();
for (let i = 1; i < 1001; i++) {
  window.myObject[i] = null;
  window.mySet.add(i);
}
Tests:
  • Object.hasOwn

     
    for (let i = 1000; i > 0; i--) {
      Object.hasOwn(window.myObject, i);
    }
  • Set.prototype.has

     
    for (let i = 1000; i > 0; i--) {
      window.mySet.has(i);
    }