Question
X and Y are asked to write a program to sum the rows of a 2x2 matrix stored in an array A.
X writes the code (Code A) as follows:
for n = 0 to 1
sumRow1[n] = A[n][0] + A[n][1]
end
Y writes the code (Code B) as follows:
sum Row 1[0] = A[0][0] + A[0][1]
sum Row1[1] = A[1][0] + A[1][1]
Which of the following statements is correct about these codes if no loop unrolling is done by the compiler?
Code A would execute faster than Code B.
Code B would execute faster than Code A.
Code A is logically incorrect
Code B is logically incorrect
Answers
Answered by
46
Answer:
b faster than a
Code B would execute faster than Code A.
Answered by
5
Code B would execute faster than Code A is correct about these codes if no loop unrolling is done by the compiler ( option b is correct answer)
- X writes the code (Code A) as follows:
- for n = 0 to 1
- sumRow1[n] = A[n][0] + A[n][1]
- Y writes the code (Code B) as follows:
- sum Row 1[0] = A[0][0] + A[0][1]
- sum Row1[1] = A[1][0] + A[1][1]
- Both Code A and Code B take two steps to complete the coding, and after that both them give the output.
- so, for that case we consider the overhead Looping matter to find out what code run faster.
- A technique for transforming loops called "loop unrolling" aids in streamlining a program's execution time. Iterations are essentially eliminated or decreased. When a loop is unrolled, loop control and loop test instructions are removed, which speeds up the programme.
- In Code B the number of overhead Looping is more than Code A.
Hence, Code B would execute faster than Code A
#SPJ2
Similar questions