Loop (v4)

Revision 4 of this benchmark created on


Setup

const iterations = 10000
const myArray = Array.from(Array(iterations).keys())
let total = 0

Test runner

Ready to run.

Testing in
TestOps/sec
For
for (let i = 0; i < myArray.length; i++) {
  total += myArray[i]
}
ready
While
let i = 0
while (i < myArray.length) {
  total += myArray[i]
  i++
}
ready
For...in
for (const item in myArray) {
  total += item
}
ready
For...of
for (const item of myArray) {
  total += item
}
ready
Array.forEach
myArray.forEach((item) => {
  total += item
})
ready
Array.map
myArray.map((item) => { 
      total += item
})
ready

Revisions

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