Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36
Chrome 130
Windows
Desktop
4 months ago
Test name Executions per second
Set.has multiple 10044.9 Ops/sec
Array.some multiple 7419.4 Ops/sec
Set.has single 11275.8 Ops/sec
Array.some single 12096.6 Ops/sec
Tests:
  • Set.has multiple

    x
     
    const oldData = Array.from({ length: 500 }, (x, i) => ({ id: String(i), x: 0, y: 0 }));
    const newData = Array.from({ length: 50 }, (x, i) => ({ id: String(i * 10), x: 1, y: 1 }));
    const oldDataSet = new Set(oldData.map((od) => od.id));
    for (const nd of newData) {
      const has = oldDataSet.has(nd.id);
    }
  • Array.some multiple

     
    const oldData = Array.from({ length: 500 }, (x, i) => ({ id: String(i), x: 0, y: 0 }));
    const newData = Array.from({ length: 50 }, (x, i) => ({ id: String(i * 10), x: 1, y: 1 }));
    for (const nd of newData) {
      const has = oldData.some((od) => od.id === nd.id);
    }
  • Set.has single

     
    const oldData = Array.from({ length: 500 }, (x, i) => ({ id: String(i), x: 0, y: 0 }));
    const findId = "450";
    const oldDataSet = new Set(oldData.map((od) => od.id));
    const has = oldDataSet.has(findId);
  • Array.some single

     
    const oldData = Array.from({ length: 500 }, (x, i) => ({ id: String(i), x: 0, y: 0 }));
    const findId = "450";
    const has = oldData.some((od) => od.id === findId);