Why does n++ execute faster than n=n+1?

前端 未结 10 1019
[愿得一人]
[愿得一人] 2021-01-30 22:05

In C language, Why does n++ execute faster than n=n+1?

(int n=...;  n++;)
(int n=...;  n=n+1;)

Our instructor asked

10条回答
  •  孤独总比滥情好
    2021-01-30 22:22

    It doesn't really. The compiler will make changes specific to the target architecture. Micro-optimizations like this often have dubious benefits, but importantly, are certainly not worth the programmer's time.

提交回复
热议问题