Reference no: EM132395227
Assignment: CSCI 717 Software Construction, North Dakota State University
1. (Operands and options)
Examine a library class that involves both options and operands, and discuss whether it follows the operand principle.
2. (Sentinel values for performance improvement)
Measure and compare the average performance of the following code. Describe your method, justify why your method is reasonable, and attach your running code and experiment results.
a) int [] item;
boolean find(int testValue) { boolean found =false; int i=0; while ( (!found) && (i<item.length) ) { if (item[i] == testValue)
found=true;
else
i++;
}
return found;
}
b) int [] item;
boolean find(int testValue) { int initialValue = item[item.length-1]; item[item.length-1] = testValue;
int i=0; while (item[i] !=testValue) { i++;
}
item[item.length-1] = initialValue; return i< item.length-1 || testValue==initialValue;
}
3. (Loop unrolling for performance improvement)
Measure and compare the average performance of the following code (suppose numIterations is large enough). Describe your method, justify why your method is reasonable, and attach your running code and experiment results.
a) double ComputeSum(int numIterations) {
int i;
double sum = 0.0; for (i = 0; i < numIterations; i++) { sum += 1.0;
}
return sum;
}
b) 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<numIterations; i++) { sum += 1.0;
}
return sum;
}