find unique

Benchmark created on


Setup

const SIZE = 100000;
const randomIntArray = _.times(SIZE, () => _.random(1, 1000)); // Adjust range as needed

Test runner

Ready to run.

Testing in
TestOps/sec
青蛙 code
function getUniqueNumber (items) {
  let arr = [];
  items.forEach((i) => {
    if (arr.includes(i)) return;
    arr.push(i);
  });
  return arr;
}

getUniqueNumber(randomIntArray )
ready
大猩猩
function getUniqueNumber (items) {
  const uniqSet = new Set();

  items.forEach((num) => {
    uniqSet.add(num);
  });
  
  return Array.from(uniqSet);
}
getUniqueNumber(randomIntArray )
ready

Revisions

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