0

I know there have been a number of questions asked regarding the performance boost of using a pre increment (decrement) vs post. And from what I can infer, the majority of C/C++ compilers will change

for (int i =0; i<N; i++)
{
...
}

to the following as an optimization

for (int i =0; i<N; ++i)
{
...
}

I have been doing a lot of code review lately, I find many instances where I could change i++ to ++i. The question is doing fixing just good form or in some cases it can make a difference in performance?

Meaning do the compilers I usually use: gcc and Visual C++ automatically make this optimization? Information is also welcome about other well used compiles as well.

Dave S
  • 973
  • 9
  • 17

1 Answers1

1

For build-in types like int or double you won't see any difference in performance.

For custom C++ types you may see a difference depending on how they have implemented the operators - only way to know is to read the code and profile it.

Jesper Juhl
  • 30,449
  • 3
  • 47
  • 70