Loop Unrolling (v4)

Revision 4 of this benchmark created on


Setup

const count = 1e6;
const data = Array.from({length: count}).map(() => Math.random());


const simpleSum = (data) => {
  let sum = 0;
  for(let i=0; i < data.length; i += 1) {
    sum += data[i];
  }
  return sum;
}

const parallelSum = (data) => {
  let sum1 = 0;
  let sum2 = 0;
  for(let i=0; i < data.length; i += 2) {
    sum1 += data[i];
    sum2 += data[i + 1];
  }
  return sum1 + sum2;
};

const lightlyParallelSum = (data) => {
  let sum = 0
  for(let i=0; i < data.length; i += 2) {
    sum += data[i] + (data[i + 1]);
  }
  return sum;
}

Test runner

Ready to run.

Testing in
TestOps/sec
Unrolled - Two Variable
parallelSum(data)
ready
Regular
simpleSum(data)
ready
Unrolled - One Variable
lightlyParallelSum(data)
ready

Revisions

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