哪一个更快/更好>或> = [英] which one is faster/better > or >=

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

问题描述




这似乎是一个疯狂的问题,但我想知道是否有人

知道这两个条件中的哪一个更好(更快,更小的内存占用,可以通过编译器等进行优化。)


1- if(i 0){//做东西}

2- if(i> = 1){//做东西}


谢谢。


-

Mahdi。

Hi

This seems like a crazy question but I wanted to find out if anyone
knows which one of those two conditions are better (faster, smaller
memory footprint, can be optimized by the compiler, etc..)

1- if(i 0) {// do stuff}
2- if(i >=1) {// do stuff}

Thanks.

--
Mahdi.

推荐答案

Mahdi写道:
Mahdi wrote:




这似乎是一个疯狂的问题,但我想知道是否有人

知道这两个条件中的哪一个更好(更快,更小) />
内存占用,可以通过编译器等进行优化。)


1- if(i 0){//做东西}

2- if(i> = 1){//做东西}
Hi

This seems like a crazy question but I wanted to find out if anyone
knows which one of those two conditions are better (faster, smaller
memory footprint, can be optimized by the compiler, etc..)

1- if(i 0) {// do stuff}
2- if(i >=1) {// do stuff}



他们都在我的机器上使用相同的x86代码。


public static void Main(string [] args)

{

for (int i = 0;我< 10; i ++)

{

if(i 0)i ++;

if(i> = 1)i ++;

}

}


中间的代码变为:


if(i 0)i ++;

0000001a test esi,esi

0000001c jle 0000001F

0000001e inc esi

if(i> = 1 )i ++;

0000001f test esi,esi

00000021 jle 00000024

00000023 inc esi


Alun Harford

They both get jitted to the same x86 code on my machine.

public static void Main(string[] args)
{
for (int i = 0; i < 10; i++)
{
if (i 0) i++;
if (i >= 1) i++;
}
}

The code in the middle becomes:

if (i 0) i++;
0000001a test esi,esi
0000001c jle 0000001F
0000001e inc esi
if (i >= 1) i++;
0000001f test esi,esi
00000021 jle 00000024
00000023 inc esi

Alun Harford


他们在同一时间执行。
They execute in the same time.


Mahdi写道:
Mahdi wrote:




这似乎是一个疯狂的问题,但我想知道是否有人

知道这两个条件中的哪一个更好(更快,更小

内存占用,可以通过编译器等进行优化。)


1- if(i 0){//做东西}

2- if(i> = 1){//做东西}
Hi

This seems like a crazy question but I wanted to find out if anyone
knows which one of those two conditions are better (faster, smaller
memory footprint, can be optimized by the compiler, etc..)

1- if(i 0) {// do stuff}
2- if(i >=1) {// do stuff}



应该绝对没有区别。


-

Rudy Velthuis http://rvelthuis.de


Quotation承认自卑。 - Ralph Waldo Emerson

There should absolutely be no difference.

--
Rudy Velthuis http://rvelthuis.de

"Quotation confesses inferiority." -- Ralph Waldo Emerson


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

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