Code 1 :
for(i=0; i<1000; i++)
for(j=0; j<100; j++)
x = y;
Code 2 :
for(i=0; i<100; i++)
for(j=0; j<1000; j++)
x = y;
thanks.
Depends upon the optimizer - both execute 100,000 assignments in the end. If the optimizer is good, it will detect that you are assigning x from y without any computation, so it would optimize out the loops and just assign y to x once. Read More
Ignoring optimization, I would say code 2 is minutely faster because it doesn't have to initialize the inner loop as often as code 1. Other than that, they are both the same. Read More