When is assembly faster than C?

前端 未结 30 2374
挽巷
挽巷 2020-12-02 03:18

One of the stated reasons for knowing assembler is that, on occasion, it can be employed to write code that will be more performant than writing that code in a higher-level

30条回答
  •  有刺的猬
    2020-12-02 03:53

    Only when using some special purpose instruction sets the compiler doesn't support.

    To maximize the computing power of a modern CPU with multiple pipelines and predictive branching you need to structure the assembly program in a way that makes it a) almost impossible for a human to write b) even more impossible to maintain.

    Also, better algorithms, data structures and memory management will give you at least an order of magnitude more performance than the micro-optimizations you can do in assembly.

提交回复
热议问题