Loop once vs twice

Benchmark created on


Setup

let a = []
let doubles = []
let squares = []
let i = 1000
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(a * 2)
	squares.push(a * a)
})
ready
loop twice
a.forEach(num => {
	doubles.push(a * 2)
})

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

Revisions

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