Script Preparation code:
x
 
var ids = [''];
var entities = { '': { id: '', number: 10000 } };
var id = '';
for (let i = 0; i < 10000; i++) {
  id = String(i);
  ids.push(id);
  entities[id] = { id, number: i }
}
function getRandomInt(min, max) {
  min = Math.ceil(min);
  max = Math.floor(max);
  return Math.floor(Math.random() * (max - min) + min); //The maximum is exclusive and the minimum is inclusive
}
var idsFind = [''];
for (let i = 0; i < 100; i++) {
  idsFind.push(String(getRandomInt(0, 20000)));
}
Tests:
  • array.includes

     
    var result = [];
    for (const id of idsFind) {
      if (ids.includes(id)) {
        result.push(entities[id])
      }
    }
    return result
  • Object.prototype.hasOwnProperty

     
    var result = [];
    for (const id of idsFind) {
      if (Object.prototype.hasOwnProperty.call(entities, id)) {
        result.push(entities[id])
      }
    }
    return result
  • object.hasOwnProperty

     
    var result = [];
    for (const id of idsFind) {
      if (entities.hasOwnProperty(id)) {
        result.push(entities[id])
      }
    }
    return result
  • Reflect.has

     
    var result = [];
    for (const id of idsFind) {
      if (Reflect.has(entities, id)) {
        result.push(entities[id])
      }
    }
    return result
  • object[field]

     
    var result = [];
    for (const id of idsFind) {
      if (entities[id] != null) {
        result.push(entities[id])
      }
    }
    return result
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    array.includes
    Object.prototype.hasOwnProperty
    object.hasOwnProperty
    Reflect.has
    object[field]

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: one year ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36
Chrome 113 on Windows
View result in a separate tab
Test name Executions per second
array.includes 1411.2 Ops/sec
Object.prototype.hasOwnProperty 65704.2 Ops/sec
object.hasOwnProperty 137055.4 Ops/sec
Reflect.has 66023.7 Ops/sec
object[field] 136134.0 Ops/sec