Should we still be optimizing “in the small”?

后端 未结 22 2131
旧时难觅i
旧时难觅i 2020-12-05 11:32

I was changing my for loop to increment using ++i instead of i++ and got to thinking, is this really necessary anymore? Surely today\'s compilers

22条回答
  •  生来不讨喜
    2020-12-05 12:04

    Those optimizations are still relevant. Regarding your example, using ++i or i++ on a built-in arithmetic type has no effect.

    In case of user defined increment/decrement operators, ++i is preferable, because it doesn't imply copying the incremented object.

    So a good coding style is to use prefix increment/decrement in for loops.

提交回复
热议问题