Array vs Set (forEach, for of, for) (v4)

Revision 4 of this benchmark created on


Setup

const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
const set = new Set(arr)

Test runner

Ready to run.

Testing in
TestOps/sec
Set forEach
let i = 0

set.forEach(val => {
	i += val
})
ready
Set for of
let i = 0

for (const val of set) {
	i += val
}
ready
Set for
let i = 0

for (let a = set.length - 1; a >= 0; --a) {
	i += set[a]
}
ready
Array forEach
let i = 0

arr.forEach(val => {
	i += val
})
ready
Array for of
let i = 0

for (const val of arr) {
	i += val
}
ready
Array for
let i = 0

for (let a = arr.length - 1; a >= 0; --a) {
	i += arr[a]
}
ready

Revisions

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