大于运算符Vs等于运算符:哪一个有效? [英] Greater than operator Vs Equal to operator : Which one is efficient?
问题描述
大家好,
哪一个是昂贵的操作?
''>''或''==" ?
我知道这不重要。但是,如果我执行这个
操作数百万次,我宁愿选择更好的选择。
我的直觉是''>' '应该有效率。但是,当
转换为汇编代码时,它生成的全部是cmpl。指令
(gcc -S< prog.c>)。所以,我的问题是::如何执行cmpl执行的cmpl>
指令?
例如:(1)if(n == 0)vs if(n> 0)
(2)if(len == 12)vs if(len< 13)
谢谢提前。
问候,
Vivek
web: http://students.iiit.net/~vivek/
hy********@yahoo.com (Vivek Mandava)写道:
哪一个是昂贵的操作?
''>''或''==" ?
C标准没有定义这些操作的性能。
我知道这不重要。但是,如果我正在执行这个数百万次的操作,我宁愿选择更好的选择。
我的直觉是''>''应该是高效的。然而,当翻译成汇编代码时,它生成的全部是cmpl。指令
(gcc -S< prog.c>)。所以,我的问题是::如何通过cpu执行cmpl
指令?
这不是C问题,而是一个问题关于特定平台上的汇编程序/机器代码
。这是偏离主题的;请在新闻组中询问
致力于对相关CPU进行编程。
Martin
On星期五,05 Sep 2003 01:25:30 -0700,Vivek Mandava写道:
大家好,
哪一个是昂贵的操作?
我认为这取决于平台和编译器。
int main()
int i ,j;
i = INT_MAX;
j = INT_MAX;
print_system_time();
while(1){
if(i == 0){
break;
} else {< br $>
++我;
}
}
print_system_time();
while(1){
if(j< 1){
break;
} else {\\ n br $>
++ j;
}
}
print_system_time;
>
返回0;
}
hth
-
NPV
Linux是Lego因为Windows是Fisher Price。 - J Frink医生
" Vivek Mandava" < HY ******** @ yahoo.com>在消息中写道
news:bb ************************** @ posting.google.c om ...Hello All,
哪一个是昂贵的操作?
''>''或''==" ?
我知道这不重要。但是,如果我正在执行这个数百万次的操作,我宁愿选择更好的选择。
我的直觉是''>''应该是高效的。然而,当翻译成汇编代码时,它生成的全部是cmpl。指令
(gcc -S< prog.c>)。所以,我的问题是::如何通过cpu执行cmpl
指令?
为什么不在你的平台上特别询问新闻组?
-
杰夫
Hello All,
Which one is an expensive operation?
''>'' or ''==" ?
I know this won''t matter much. However, if I''m executing this
operation million times, I would prefer the better choice.
My gut feeling is that ''>'' should be efficient. However, when
translated to assembly code all it generates is "cmpl" instruction
(gcc -S <prog.c>). So, my question here is :: how is "cmpl"
instruction executed by the cpu?
Ex: (1) if (n == 0) vs if (n > 0)
(2) if (len == 12) vs if (len < 13)
Thanks in advance.
Regards,
Vivek
web: http://students.iiit.net/~vivek/
hy********@yahoo.com (Vivek Mandava) writes:
Which one is an expensive operation?
''>'' or ''==" ?
The C standard doesn''t define the performance of these operations.
I know this won''t matter much. However, if I''m executing this
operation million times, I would prefer the better choice.
My gut feeling is that ''>'' should be efficient. However, when
translated to assembly code all it generates is "cmpl" instruction
(gcc -S <prog.c>). So, my question here is :: how is "cmpl"
instruction executed by the cpu?
This is not a C question, but a question about assembler/machine code
on a specific platform. It is off-topic here; please ask in a newsgroup
dedicated to programming the CPU in question.
Martin
On Fri, 05 Sep 2003 01:25:30 -0700, Vivek Mandava wrote:
Hello All,
Which one is an expensive operation?
That would depend on both plattform and compiler I think.
int main()
int i,j;
i=INT_MAX;
j=INT_MAX;
print_system_time();
while(1) {
if (i == 0) {
break;
} else {
++i;
}
}
print_system_time();
while(1) {
if (j < 1) {
break;
} else {
++j;
}
}
print_system_time;
return 0;
}
hth
--
NPV
"Linux is to Lego as Windows is to Fisher Price." - Doctor J Frink
"Vivek Mandava" <hy********@yahoo.com> wrote in message
news:bb**************************@posting.google.c om...Hello All,
Which one is an expensive operation?
''>'' or ''==" ?
I know this won''t matter much. However, if I''m executing this
operation million times, I would prefer the better choice.
My gut feeling is that ''>'' should be efficient. However, when
translated to assembly code all it generates is "cmpl" instruction
(gcc -S <prog.c>). So, my question here is :: how is "cmpl"
instruction executed by the cpu?
Why don''t ask in your platform specific newsgroup ?
--
Jeff
这篇关于大于运算符Vs等于运算符:哪一个有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!