Set constructor vs set.add

Benchmark created on


Setup

const a = [];

for (i = 0; i <= 1_000_000; i++) {
	a[i] = i;
}

Test runner

Ready to run.

Testing in
TestOps/sec
Set constructor
const s = new Set(a);


ready
Set.add
const s = new Set();

for (i in a) {
	s.add(i)
}
ready

Revisions

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