for example
for (int i=1;i<10000;i++)
{
j++;
k++;
}
or
for (int i=1;i<10000;i++)
{
j++;
}
for (int i=1;i<10000;i++)
{
k++;
}
Note 1: in c# is it still better to use ++i instead of i++?
Note 2: A good thing that if we spilt a large loop into separate simple loops is that then we can transform it into Linq form, such as enumerable.range(1,10000).forall(x=>j++) so in the lambda expression or delegate i don’t have to put multiple statements together.
(1) almost the same
(2) Use one loop if the code in the loop is quite simple, like
i++orj++. Note that using separate loops for 2 complex methods is probably faster than one loop:Separated loops improves the hit rate of the registers. If you put them in one loop, the time reduced by 1000 loops is less than the more time cost by register miss.