Is Loop Hoisting still a valid manual optimization for C code?

后端 未结 8 1135
感动是毒
感动是毒 2021-01-01 15:08

Using the latest gcc compiler, do I still have to think about these types of manual loop optimizations, or will the compiler take care of them for me well enough?

8条回答
  •  失恋的感觉
    2021-01-01 15:27

    Write the code, profile it, and only think about optimising it when you have found something that is not fast enough, and you can't think of an alternative algorithm that will reduce/avoid the bottleneck in the first place.

    With modern compilers, this advice is even more important - if you write simple clean code, the compiler's optimiser can often do a better job of optimising the code than it can if you try to give it snazzy "pre-optimised" code.

提交回复
热议问题