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.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Pythagorean Triplet with given sum using single loop
- Abstraction of Binary Search
- Check if a palindromic matrix can be formed from the given array elements
- Applications of String Matching Algorithms
- Cocke–Younger–Kasami (CYK) Algorithm
- Mathematics concept required for Deep Learning
- Applications of Dijkstra's shortest path algorithm
- Single source shortest path between two cities
- Travelling Salesman Problem | Greedy Approach
- Implementation of Tic-Tac-Toe for 2 person game (User vs. User)
- Possible permutations at a railway track
- Minimum Cost using Dijkstra by reducing cost of an Edge
- Sorting algorithm visualization : Heap Sort
- Difference between C-LOOK and C-SCAN Disk Scheduling Algorithm