For loop performance difference, and compiler optimization

前端 未结 7 1334
耶瑟儿~
耶瑟儿~ 2021-02-14 00:40

I chose David\'s answer because he was the only one to present a solution to the difference in the for-loops with no optimization flags. The other answers demonstrate what

7条回答
  •  眼角桃花
    2021-02-14 01:22

    Checking the assembly output is really the only way to illuminate such things.

    Compiler optimisations will do a great deal of things, including things that are not strictly "standard compliant" (although, that is not the case with -O1 and -O2, to my knowledge) - for instance check, -Ofast switch.

    I have found this helpful: http://gcc.godbolt.org/, and with your demo code here

提交回复
热议问题