Measure and compare the average performance of the following code (suppose as is large enough). Describe your method, justify why your method is reasonable, and attach your running code and experiment results. This idea is Loop unrolling for performance improvement.
1a)
double ComputeSum(int numIterations) {
int i;
double sum = 0.0; for (i = 0; i < numIterations; i++) { sum += 1.0;
}
return sum;
}
1b) double ComputeSum (int numIterations) { double sum0, sum1, sum2, sum3, sum4, sum5, sum6, sum7; int i;
double sum = 0.0;
sum0 = sum1 = sum2 = sum3 = sum4 = sum5 = sum6 = sum7 = 0.0;
for (i = 0; (i+7) < numIterations; i += 8) { sum0 += 1.0; sum1 += 1.0; sum2 += 1.0; sum3 += 1.0; sum4 += 1.0;
sum5 += 1.0; sum6 += 1.0; sum7 += 1.0;
}
sum = sum0 + sum1 + sum2 + sum3 +sum4 +sum5 + sum6 + sum7; for (;i
}
return sum;
}