++ u或u ++哪个更快? [英] ++u or u++ which is faster?
本文介绍了++ u或u ++哪个更快?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
如果U是用户定义的类型,最近我被问到关于++ U或U ++是否更快
的问题。答案是什么?
谢谢
解决方案
医生写道:大家好,
如果U是用户定义的类型,最近我被问到关于++ U或U ++是否更快的问题。答案是什么?
谢谢
http://www.parashift.com/c++-faq-lit...html#faq-13.12
-
Sumit Rajan< sumitrajan AT亚历山大DOT cc>
医生张贴:
<尽管如此,我还是被问到如果U是用户定义类型,是否更快地使用++ U或U ++的问题。答案是什么?
谢谢
++你的速度更快。
总是使用++你。除非你需要,否则永远不要使用u ++。
-JKop
通常,operator ++(int)的实现如下: br />
T operator ++(int)
{
T tmp = * this;
+ + * this;
返回tmp;
}
如果编译器无法优化初始化暂时
然后使用u ++会变慢。这就是为什么通常更好地使用
预增量/预减量而不是后减量/后增量。
VH
" The Doctor" <做**** @ nospam.com>在消息中写道
新闻:Xn ********************************** @ 61.9 .191 .5 ...大家好,
最近我被问到如果U是用户,++ U或U ++是否更快的问题定义的类型。答案是什么?
谢谢
Hi all,
Recently I was asked the question about whether ++U or U++ is
faster if U is a user defined type. What''s the answer?
Thank you
解决方案
The Doctor wrote:Hi all,
Recently I was asked the question about whether ++U or U++ is
faster if U is a user defined type. What''s the answer?
Thank you
http://www.parashift.com/c++-faq-lit...html#faq-13.12
--
Sumit Rajan <sumitrajan AT alexandria DOT cc>
The Doctor posted:
Hi all,
Recently I was asked the question about whether ++U or U++ is
faster if U is a user defined type. What''s the answer?
Thank you
++u is faster.
Always use ++u. Never use u++ unless you need to.
-JKop
Usually operator ++ (int) is implemented like this:
T operator ++ (int)
{
T tmp = *this;
++*this;
return tmp;
}
If compiler isn''t able to optimize away the initialization of the temporary
then using u++ is slower. That''s why it is usually better to use
pre-increment/pre-decrement instead of post-decrement/post-increment.
VH
"The Doctor" <do****@nospam.com> wrote in message
news:Xn**********************************@61.9.191 .5...Hi all,
Recently I was asked the question about whether ++U or U++ is
faster if U is a user defined type. What''s the answer?
Thank you
这篇关于++ u或u ++哪个更快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文