Task

Benchmark created on


Setup

function getRandomArbitrary(min, max) {
  return Math.round(Math.random() * (max - min) + min);
}
const data = [];
for (let i = 0; i < 10000000; i += 1) {
  data.push(getRandomArbitrary(1, 1000));
}
const func1 = (arr) => {
  const result = []
  for (let i = 0; i < arr.length; i += 1) {
    if (result.includes(arr[i])) continue
    result.push(arr[i])
  }
  return result
}

const func2 = (arr) => {
  const result = [...new Set(arr)]
  return result
}

const func3 = (arr) => {
  const hash = {};
  const result = [];
  for (let i = 0; i < arr.length; i += 1) {
    if (hash[arr[i]]) continue;
    result.push(arr[i]);
    hash[arr[i]] = true;
  }
  return result;
};

Test runner

Ready to run.

Testing in
TestOps/sec
Test1
func1(data)
ready
Test2
func2(data)
ready
Test3
func3(data)
ready

Revisions

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