Array vs Set Iteration

Benchmark created on


Setup

const bigArray = Array(100_000).fill(0).map((i, index) => index);
const bigSet = new Set(bigArray);

Test runner

Ready to run.

Testing in
TestOps/sec
Array iteration
let count = 0;
for (const v of bigArray) {
	count += 1;
}
ready
Set iteration
let count = 0;
for (const v of bigSet) {
	count += 1;
}
ready
For Loop Iteration
let count = 0;
for (let i = 0; i < bigArray.length; i += 1) {
	let v = bigArray[i];
	count += 1;
}
ready
For Loop + Initialize from Set
let count = 0;
const arrayFromSet = Array.from(bigSet);
for (let i = 0; i < arrayFromSet.length; i += 1) {
	let v = arrayFromSet[i];
	count += 1;
}
ready

Revisions

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