In: Computer Science
Using the C Programming language, write a program that sums an array of 50 elements. Next, optimize the code using loop unrolling. Loop unrolling is a program transformation that reduces the number of iterations for a loop by increasing the number of elements computed on each iteration. Generate a graph of performance improvement. Tip: Figure 5.17 in the textbook provides an example of a graph depicting performance improvements associated with loop unrolling.
Marking:-
Optimize the code for an array of 50 elements using loop unrolling. Prepare a graph that show the performance improvements. (30)
Loop unrolling is a loop transformation technique that helps to optimize the execution time of a program. We basically remove or reduce iterations. Loop unrolling increases the program’s speed by eliminating loop control instruction and loop test instructions.
c program without loop unrollong:
#include<stdio.h> int main() } |
now with loop unrolling:
#include<stdio.h> int main() printf("sum is %d",sum); } |
Advantage of loop unrolling is that it makes the program fast. However, it makes our program bit lengthy.