Loop Unrolling

Benchmark created on


Setup

const simpleSum = (count) => {
  let sum = 0;
  for(let i=0; i < count; i += 1) {
    sum += i + 1;
  }
  return sum;
}

const parallelSum = (count) => {
  let sum1 = 0;
  let sum2 = 0;
  for(let i=0; i < count; i += 2) {
    sum1 += i + 1;
    sum2 += i + 2;
  }
  return sum1 + sum2 - (count % 2 ? (count + 1) : 0);
};

Test runner

Ready to run.

Testing in
TestOps/sec
Unrolled
parallelSum(1e6)
ready
Regular
simpleSum(1e6)
ready

Revisions

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