How do I find how C++ compiler implements something except inspecting emitted machine code?

后端 未结 8 1788
渐次进展
渐次进展 2020-12-17 14:28

Suppose I crafted a set of classes to abstract something and now I worry whether my C++ compiler will be able to peel off those wrappings and emit really clean, concise and

8条回答
  •  既然无缘
    2020-12-17 15:14

    Timing the code will directly measure its speed and can avoid looking at the disassembly entirely. This will detect when compiler, code modifications or subtle configuration changes have affected the performance (either for better or worse). In that way it's better than the disassembly which is only an indirect measure.

    Things like code size can also serve as possible indicators of problems. At the very least they suggest that something has changed. It can also point out unexpected code bloat when the compiler should have boiled down a bunch of templates (or whatever) into a concise series of instructions.

    Of course, looking at the disassembly is an excellent technique for developing the code and helping decide if the compiler is doing a sufficiently good translation. You can see if you're getting your money's worth, as it were.

    In other words, measure what you expect and then dive in if you think the compiler is "cheating" you.

提交回复
热议问题