Coding Practices which enable the compiler/optimizer to make a faster program

后端 未结 30 1948
一个人的身影
一个人的身影 2020-12-02 03:24

Many years ago, C compilers were not particularly smart. As a workaround K&R invented the register keyword, to hint to the compiler, that maybe it woul

30条回答
  •  不知归路
    2020-12-02 04:15

    You're getting good answers here, but they assume your program is pretty close to optimal to begin with, and you say

    Assume that the program has been written correctly, compiled with full optimization, tested and put into production.

    In my experience, a program may be written correctly, but that does not mean it is near optimal. It takes extra work to get to that point.

    If I can give an example, this answer shows how a perfectly reasonable-looking program was made over 40 times faster by macro-optimization. Big speedups can't be done in every program as first written, but in many (except for very small programs), it can, in my experience.

    After that is done, micro-optimization (of the hot-spots) can give you a good payoff.

提交回复
热议问题