Set vs Array deduplication

Benchmark created on


Setup

function randomNumber(min, max) {
    return Math.random() * (max - min) + min;
}

const testSet = new Set();
const testArray = [];

Test runner

Ready to run.

Testing in
TestOps/sec
Set
const num = randomNumber(1, 100).toString();

if (!testSet.has(num)) {
	testSet.add(num);
}
ready
Array
const num = randomNumber(1, 100).toString();

if (!testArray.includes(num)) {
	testArray.push(num);
}
ready

Revisions

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