test perf loops

Benchmark created on


Setup

const found = [];

const batch = Array.from({ length: 1000 }, (_, i) => ({
  WINDOWKEY: `windowKey${i + 1}`,
}));

// Fonction pour générer un nombre aléatoire entre min et max (inclus)
function getRandomInt(min, max) {
  return Math.floor(Math.random() * (max - min + 1)) + min;
}

// Génération du tableau de 14 entrées
let results = [];
for (let i = 0; i < 14; i++) {
  let randomNum = getRandomInt(1, 1000);
  results.push({ windowKey: `windowKey${randomNum}` });
}

Teardown

console.log(found);

Test runner

Ready to run.

Testing in
TestOps/sec
forof
for (const result of results) {
  const filteredBatch = batch.filter((b) => b.WINDOWKEY === result.windowKey);
  if (filteredBatch.length !== 0) {
    found.push(...filteredBatch);
  }
}
ready
double for
for (let i = 0, len = results.length; i < len; i++) {
  const result = results[i];
  for (let j = 0, lenj = batch.length; j < lenj; j++) {
    const b = batch[j];
    if (b.WINDOWKEY === result.windowKey) {
      found.push(b);
    }
  }
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.