Compute size inside/outside a loop

Benchmark created on


Setup

const array = Array.from({ length: 10000000 }, (_, i) => i);

Test runner

Ready to run.

Testing in
TestOps/sec
Inside Loop
let sumFor = 0;
for (let i = 0; i < array.length; i++) {
  sumFor += array[i];
}
ready
Outside Loop
let sumFor = 0;
const size = array.length;
for (let i = 0; i < size; i++) {
  sumFor += array[i];
}
ready

Revisions

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