Iterating over an array

Benchmark created on


Setup

const arr = new Array(100_000)
for(let i; i < arr.length; i++){
	arr[i] = Math.random()
}

Test runner

Ready to run.

Testing in
TestOps/sec
Basic for
let sum = 0
for(let i; i < arr.length; i++){
	sum += arr[i]
}
ready
for...in
let sum = 0
for (let i in arr) {
	sum += arr[i]
}
ready
for...of
let sum = 0
for (let n of arr) {
	sum += n
}
ready
Array.forEach
let sum = 0
arr.forEach(n => sum += n)
ready
Array.reduce
let sum = arr.reduce((acc, c) => acc += c, 0)
ready

Revisions

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