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 |
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);
}
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);
}
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);
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);