Check the following C example, why is one loop so much slower than two loops?
Suppose we have to add some values to array a1 and c1 of b1 and d1 respectively then there is big time difference in execution of both code..
const int n=100000;
for(int j=0;j<n;j++){
a1[j] += b1[j];
c1[j] += d1[j];
}
This loop is executed 10,000 times via another outer for loop. to speed it up, I changed the code to:
for(int j=0;j<n;j++){
a1[j] += b1[j];
}
for(int j=0;j<n;j++){
c1[j] += d1[j];
}
I don't think there should be any execution time difference but it is showing.