Loop once vs twice (v2)

Revision 2 of this benchmark created on


Setup

let a = []
let doubles = []
let squares = []
let i = 5000
while (i--) {
	a.push(i)
}

Teardown

a = []
doubles = []
squares = []

Test runner

Ready to run.

Testing in
TestOps/sec
loop once
// double and square
a.forEach(num => {
	doubles.push(num * 2)
	squares.push(num * num)
})
ready
loop twice
a.forEach(num => {
	doubles.push(num * 2)
})

a.forEach(num => {
	squares.push(num * num)
})
ready

Revisions

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