运算符 x++;和++x;对于 int. 哪个更快?为什么?
他们说 ++i
更快,但我不明白为什么。有人可以向我展示这些运算符的汇编代码吗?
Possible Duplicate:
Is there a performance difference between i++ and ++i in C++?
They say that ++i
is faster but I don't understand why.Can anybody show me assembler codes of these operators?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
++i
绝对与i++
一样快,但它可能更快。原因在于执行。
为了实现
i++
,该实现需要生成i
的临时副本,这与++i
的实现不同。但智能编译器可以优化这个临时文件的生成,当然对于 POD 类型也是如此。
++i
is definitiely as fast asi++
but it may be faster.The reason is the implementation.
In order to implement
i++
the implementation needs to generate a temporary copy ofi
unlike the implementation for++i
.But smart compilers can optimize the genration of this temporary, they certainly do for POD types.
是否为此表达式生成更快的代码取决于编译器和情况。
It depends on the compiler and the situation if it generates faster code for this expression.