Set add vs Array push

Benchmark created on


Setup

const ratioOfDuplicates = 4;
const elementsToAdd = Array(100000).fill().map((_, i) => Math.floor(i/ratioOfDuplicates));

Test runner

Ready to run.

Testing in
TestOps/sec
Set
const s = new Set();
for(v of elementsToAdd) {
	s.add(v);
}
const out = Array.from(s);
ready
Array
const a = [];
for (v of elementsToAdd) {
	a.push(v);
}
const out = Array.from(new Set(a));
ready

Revisions

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