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.
Hello Hello Hello Hello Hello
Program 2 is more efficient than program 1 because in program 1 there is a need to check the value of i and increment the value of i every time round the loop. So small loops like this or loops where there is fixed number of iterations are involved can be unrolled completely to reduce the loop overhead.
- Increases program efficiency.
- Reduces loop overhead.
- If statements in loop are not dependent on each other, they can be executed in parallel.
- Increased program code size, which can be undesirable.
- Possible increased usage of register in a single iteration to store temporary variables which may reduce performance.
- Apart from very small and simple codes, unrolled loops that contain branches are even slower than recursions.
This article is contributed by Harsh Agarwal. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Minimum increment or decrement operations required to make the array sorted
- Queries to find the left-most given type integer in a binary array
- Blowfish Algorithm with Examples
- Longest Increasing Subsequence using Longest Common Subsequence Algorithm
- Minimum number of additons to make the string balanced
- Find a pair (n,r) in an integer array such that value of nPr is maximum
- Find a pair (n,r) in an integer array such that value of nCr is maximum
- Minimize the cost of partitioning an array into K groups
- Maximize the Expression | Bit Manipulation
- Check whether two strings can be made equal by copying their characters with the adjacent ones
- Sentinel Linear Search
- Count number of Special Set
- Color all boxes in line such that every M consecutive boxes are unique
- Widest Path Problem | Practical application of Dijkstra's Algorithm