Array forEach vs Array for of vs Set forEach vs Set for of (v3)

Revision 3 of this benchmark created on


Setup

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

Test runner

Ready to run.

Testing in
TestOps/sec
array forEach
let i = 0

array.forEach(value => {
	i += value
})
ready
array for of
let i = 0

for (const value of array) {
	i += value
}
ready
set forEach
let i = 0

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

for (const value of set) {
	i += value
}
ready

Revisions

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