Array vs Set iteration

Benchmark created on


Setup

var set = new Set();
var arr = [];

for (let i = 0; i < 10000; i++) {
	set.add(() => Math.random());
	arr.push(() => Math.random());
}

Test runner

Ready to run.

Testing in
TestOps/sec
Set (forEach)
set.forEach((cb) => { cb(); })
ready
Set (for / of)
for (cb of set) {
	cb();
}
ready
Array (forEach)
arr.forEach((cb) => { cb(); })
ready
Array (for / of)
for (cb of arr) {
	cb();
}
ready

Revisions

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