set vs array

Benchmark created on


Setup

const arr = ['COSP',
  'CRAC_AVEC_CB',
  'CRAC_SANS_CB',
  'UNKNOWN',
  'RETAILER'
];

const set = new Set(arr);

const data = new Array(10_000).fill("").map(_ => arr.at(Math.floor(Math.random()*arr.length*2)) || "OTHER")

Test runner

Ready to run.

Testing in
TestOps/sec
array
data.map(e => arr.includes(e)).reduce((t, i) => i ? t : t+1, 0)
ready
set
data.map(e => set.has(e)).reduce((t, i) => i ? t : t+1, 0)
ready

Revisions

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