Set vs Array data (v2)

Revision 2 of this benchmark created on


Setup

// Function to generate a random string of a given length
const generateRandomString = (length = 10) => {
  const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
  let result = '';
  for (let i = 0; i < length; i++) {
    result += characters.charAt(Math.floor(Math.random() * characters.length));
  }
  return result;
};

// Create an array of 50 random strings
const arrayData = Array.from({ length: 50 }, () => generateRandomString());
const setData = new Set(arrayData)

Test runner

Ready to run.

Testing in
TestOps/sec
Set
console.log(setData.has("test"))

ready
Array
console.log(arrayData.includes("test"))
ready

Revisions

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