Should we still be optimizing “in the small”?

后端 未结 22 2132
旧时难觅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 11:47

    Don't try to guess what your compiler is doing. If you've already determined that you need to optimize something at this level, isolate that bit and look at the generated assembly. If you can see that the generated code is doing something slow that can be improved, by all means fiddle with it at a code level and see what happens. If you really need control, rewrite that bit in assembly and link it in.

    This is a pain in the ass, but the only way to really see what is happening. Be aware that all such tight optimizations may become useless once you change anything (different CPU, different compiler, even different cache, etc.) and it's a sunk cost.

提交回复
热议问题