哪个更快? [英] which is faster ?

查看:65
本文介绍了哪个更快?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下哪一项更快,为什么?


if(x == 1){


}





if(x!= 0){


}

which of the following is faster and why ?

if ( x == 1 ) {

}

or

if ( x != 0 ) {

}

推荐答案

if(x!= 0)如果你的cpu是x86,否则我不知道。


if你选择优化,我不知道

if (x!=0) if your cpu is x86, otherwise i don''t know.

if you choose optimise, i don''t know either


junky_fel ... @ yahoo.co.in写道:
junky_fel...@yahoo.co.in wrote:
以下哪一项更快,为什么?

如果(x == 1){

}


if(x!= 0){

}
which of the following is faster and why ?

if ( x == 1 ) {

}

or

if ( x != 0 ) {

}




这取决于你的平台,标准无关于

这个。为什么不在机器上自己测试?


您还应注意上述测试不相同。如果x是
2那么第一个测试将是假,而第二个测试将为真。你好b / b
应该更担心编写清楚的代码,这对你的情况有意义,让编译器担心如何最好地执行

为你测试,因为它无疑比你更了解如何最好地优化这样的表达。


Rob Gamble



It depends on your platform, the Standard has nothing to say about
this. Why don''t you test it yourself on your machine?

You should also note that the above tests are not equivalent. If x is
2 then the first test will be false while the second will be true. You
should be more worried about writing clear code that makes sense in
your situation and let the compiler worry about how to best perform the
test for you since it undoubtedly knows more than you do about how best
to optimize such an expression.

Rob Gamble


2005年5月16日04:57:30 -0700, ju **********@yahoo.co.in 写道:
On 16 May 2005 04:57:30 -0700, ju**********@yahoo.co.in wrote:
以下哪项更快,为什么?
if(x == 1){

}


if(x!= 0){
}
which of the following is faster and why ?

if ( x == 1 ) {

}

or

if ( x != 0 ) {

}




首先回答哪个问题给你正确答案。


-

Al Balmer

Balmer Consulting
re ************************ @ att.net

这篇关于哪个更快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆